The document is unclear about the thread safety of the System.Net.WebSockets.ClientWebSocket
class.
Is it safe to call the SendAsync
method from multiple threads simultaneously?
It's thread safe enough to get some work done.
According to the source (credit to Michael Kropat for discussing it at https://www.codetinkerer.com/2018/06/05/aspnet-core-websockets.html )
Thread-safety:
- It’s acceptable to call ReceiveAsync and SendAsync in parallel. One of each may run concurrently.
- It’s acceptable to have a pending ReceiveAsync while CloseOutputAsync or CloseAsync is called.
- Attempting to invoke any other operations in parallel may corrupt the instance. Attempting to invoke a send operation while another is in progress or a receive operation while another is in progress will result in an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With