Monitor.Enter and Monitor.Exit are for calling from the same thread. But, what if I need to release the lock in a different thread than the received one?
For example: there is a shared resource and an asynchronous operation that uses this resource. The operation starts with BeginOperation and gets a lock on the share. There is also an EndOperation method that releases the lock. EndOperation usually called on another thread from the callback, so I cannot call Monitor.Exit in the EndOperation method. What is the best approach in this case? Would it be good to check the lock with AutoResetEvent instead of Monitor ?
eigenein
source share