SerialPort.set_ReadTimeout 如何抛出 IOException { NativeErrorCode = ERROR_OPERATION_ABORTED }?
在将消息从 SerialPort
发送到设备后,为了准备读回其响应,我尝试设置 ReadTimeout
并返回一个相当奇怪的错误:
System.IO.IOException was unhandled
Message="The I/O operation has been aborted because of either a thread exit or an application request.\r\n"
Source="System"
StackTrace:
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.InternalResources.WinIOError()
at System.IO.Ports.SerialStream.set_ReadTimeout(Int32 value)
at System.IO.Ports.SerialPort.set_ReadTimeout(Int32 value)
没有其他访问 SerialPort 的线程,并且没有向其注册事件处理程序(我希望这可以排除端口后面隐式线程的干扰)。
但无论如何,这对我来说似乎很奇怪:SetCommTimeouts
怎么会因 ERROR_OPERATION_ABORTED
失败?
After sending a message out a SerialPort
to a device, in preparation to read back its response, I tried setting the ReadTimeout
and got back a rather oddball error:
System.IO.IOException was unhandled
Message="The I/O operation has been aborted because of either a thread exit or an application request.\r\n"
Source="System"
StackTrace:
at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
at System.IO.Ports.InternalResources.WinIOError()
at System.IO.Ports.SerialStream.set_ReadTimeout(Int32 value)
at System.IO.Ports.SerialPort.set_ReadTimeout(Int32 value)
There are no other threads accessing the SerialPort
, and no event handlers registered with it (which I hope would rule out interference from the implicit thread behind the port).
In any case, though, it just seems weird to me: how can SetCommTimeouts
fail with ERROR_OPERATION_ABORTED
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论