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

后端 未结 2 1190
梦毁少年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

    From the documentation:

    Any public static (Shared in Visual Basic) members of this type (SerialPort) are thread safe. Any instance members are not guaranteed to be thread safe.

    So you should definetly synchronize your read/writes with locks.

提交回复
热议问题