jjzjj

ObjectDisposedExecption

全部标签

c# - 关闭 .NET SerialPort 后的 ObjectDisposedExecption

我正在使用.NET4SerialPort对象与连接到COM1的设备通信。当我完成对设备的操作后,我在SerialPort上调用Close。我不调用Dispose,但我相信Close和Dispose在这里是同义词。通常这工作得很好。然而,有时我会在一段时间后收到以下异常(我看到的时间范围为5毫秒到175毫秒):System.ObjectDisposedException:SafehandlehasbeenclosedatSystem.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean&success)atSystem.St