Introduces a semaphore to synchronize calls to SendAsync in the WriteMessage method. This ensures that we do not call SendAsync again until the previous operation has completed, which resolves the System.InvalidOperationException we were encountering.
The changes include:
Added a SemaphoreSlim instance to allow only one operation at a time.
Updated the WriteMessage method to use the semaphore, ensuring that only one SendAsync operation happens at a time.
Introduces a semaphore to synchronize calls to
SendAsync
in theWriteMessage
method. This ensures that we do not callSendAsync
again until the previous operation has completed, which resolves theSystem.InvalidOperationException
we were encountering.The changes include:
SemaphoreSlim
instance to allow only one operation at a time.WriteMessage
method to use the semaphore, ensuring that only oneSendAsync
operation happens at a time.