Mutex. If you are a developer than you heard about mutex. Mutex are used to ensure that only one thread/process has an exclusive access to a specific sections of the code. Let’s look over the following code and see if the code is correct or not? public class Foo { Mutex mutex = new Mutex(); event SomeActionEvent someActionEvent; public void Do() { mutex.WaitOne(); ... someActionEvent += OnSomeAction(); } public void OnSomeAction(...) { mutex.ReleaseMutex(); } } “WaitOne” method is used to block the current thread until we received a release signal – WaitHandler. “ReleaseMutex” is used when we want to release the lock. The above code release the mutex lock on an event handler that is executed on a different thread. The problem is that we don’t call the release mutex method from the same thread from where we call “WaitOne”. Because of this, the obtained behavior is not the one that we expect. The same problem will appear if we use mutex in com
DREAMER, CRAFTER, TECHNOLOGY ENTHUSIAST, SPEAKER, TRAINER, AZURE MVP, SOLVING HARD BUSINESS PROBLEMS WITH CUTTING-EDGE TECHNOLOGY