Is it necessary to synchronize .NET SerialPort writes/reads?

后端 未结 2 1176
梦毁少年i
梦毁少年i 2021-01-07 22:42

In my application I use the .NET SerialPort class for reading and writing data. The reading is done using the DataReceived event, I assume internally on a ThreadPool thread.

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 23:28

    Here's a great thread on the topic, with the author of the SerialPort class participating:

    MSDN: How does SerialPort handle DataReceived?

    From my experience, I've written a dozen serial communication apps for use as hardware simulators, I don't lock. I didn't know at the time if I was safe or not, but in practice, I haven't had an error yet. (a year of near constant use by 20+ testers and automated test machines) That said, my applications don't leave the company, if I were writing apps for public consumption I might take more care.

提交回复
热议问题