C
C#2y ago
kuba_z2

✅ ClientWebSocket concurrency question

Hello. Can ReceiveAsync and CloseAsync methods be used concurrently? And also the same for SendAsync and CloseAsync (this one sounds a bit funny but it's serious). The documentation doesn't say anything about concurrency for CloseAsync.
1 Reply
kuba_z2
kuba_z2OP2y ago
I have found the explanation in source code
/// 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.
/// 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.
~ https://source.dot.net/#System.Net.WebSockets/System/Net/WebSockets/ManagedWebSocket.cs,8eecb48ae7d8e666
Want results from more Discord servers?
Add your server