Thread Safety in .NET–Difference Between using Monitor.Enter and Monitor.Exit and lock
When we want to develop ThreadSafe solutions .NET two of the options that we can use are Monitor and lock. But what exactly happens when we use one and another? What are the differences between one and the other? Basically the difference is that lock really emits code that places a a Monitor inside a try…finally block. So the real difference is that lock really gives us a exception proof Monitor, since it makes sure that it gets free of that locking even if an exception occurs. So lets see a sample of that: Imagine this … Continue reading Thread Safety in .NET–Difference Between using Monitor.Enter and Monitor.Exit and lock