C# (Sharp) Programming Language Question:

How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?

Tweet Share WhatsApp

Answer:

You want the lock statement, which is the same as Monitor Enter/Exit:

lock(obj) { // code }

translates to

try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}


Download C# (Sharp) Programming Language PDF Read All 163 C# (Sharp) Programming Language Questions
Previous QuestionNext Question
How do you mark a method obsolete? How do you directly call a native function exported from a DLL?