C# (Sharp) Programming Language Question:

Download Job Interview Questions and Answers PDF

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

C# (Sharp) Programming Language Interview Question
C# (Sharp) Programming Language Interview Question

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 Interview Questions And Answers PDF

Previous QuestionNext Question
How do you mark a method obsolete? How do you directly call a native function exported from a DLL?