I'm getting the following exception "Object synchronization method was called from an unsynchronized block of code" when releasing the mutex in the code below:
int count = 0;
try
{
mutex.WaitOne();
count = requests_sent.Count;
}
catch
{
}
finally
{
mutex.ReleaseMutex();
}
requests_sent is a dictionary that is being accessed (read/write) by other threads but I have no clue why this code is throwing an exception. Anyone have any ideas?
Move the WaitOne() call above the try block. You only want to release the mutex when you know you acquired it.
You'll now also stand a chance to get a better diagnostic.
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