我已经解决这个问题很多天了,但我被困在其中,无法弄清楚。问题是当我关闭端口时,我得到了这个著名的错误
The I/O operation has been aborted because of either a thread exit or an application request
我的代码是这样的
 private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                port.ReadExisting();
                port.DiscardInBuffer();         
                if (port.IsOpen)
                {
                    port.Close();
                }
                Window1 caster = new Window1(this);
                caster.ShowDialog();
            }
            catch (IOException)
            {
            }
当port.close()执行时,我得到上述错误。如果我取消订阅数据接收事件,即使这样也会发生此错误并且不会被 catch 语句捕获。
我搜索了它并找到了许多示例,那里提供的所有解决方案都已尝试过,但是每次使用应用程序时都让我很烦。
有人可以帮我解决这个问题吗?