我在主窗口MainForm中设置了Static SerialPort,在主界面注册了一个监听事件,然后在调到子界
之前,我注销了监听事件,
serialPort.DataReceived -= new SerialDataReceivedEventHandler(serial_DataReceived);
然后在子界面Calibration中使用了SerialPort,然后重新设置了监听事件:
MainForm.serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceived2);
想实现的方式是:在子窗口关闭之前将监听事件取消,然后在主界面在重新设置监听事件,关闭子窗口后主界面实现的代码
calibrationForm = new Calibration( );
calibrationForm.ShowDialog();
if (calibrationForm.DialogResult == System.Windows.Forms.DialogResult.OK)
{
serialPort.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
}
但是现在的结果是回到主界面后返回的数据仍然在子窗口事件监听器中显示(通过Console打印返回的数据大小)
求大神指点!!!