Are condition variables & monitors used in C#?
Can someone give me an example?
Are condition variables & monitors used in C#?
Can someone give me an example?
You can use the Lock object which acts as syntactic sugar for the Monitor class.
lock(someObject)
{
// Thread safe code here.
}
http://msdn.microsoft.com/en-us/library/c5kehkcz%28VS.80%29.aspx
The direct equivalent of a condition variable in .NET is the abstract WaitHandle class. Practical implementations of it are the ManualResetEvent, AutoResetEvent, Mutex and Semaphore classes.
System.Threading.Monitor is the direct equivalent of a monitor. The lock statement makes it very easy to use, it ensures the monitor is always exited without explicitly programming the Exit() call.