ObjectDisposedExecption after closing a .NET SerialPort

ⅰ亾dé卋堺 提交于 2019-12-04 03:00:26

I've had this issue too, and since I started using the following two rules I've never seen it again.

  1. Always call Close() followed by Dispose().
  2. Never reuse a SerialPort object, always create a new one when a port needs to be reopened.

I know, they aren't much news, but its been working for me.

The call to disposed is documented behavior (see here) - I guess you try to read/write after Close (maybe in another thread). I would suggest wrapping the calls in a seperate class and setting a "closed"-flag. Then you should be able to find the problem rather fast.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!