C# (Sharp) Programming Language Question:
How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?

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);
}
lock(obj) { // code }
translates to
try {
CriticalSection.Enter(obj);
// code
}
finally
{
CriticalSection.Exit(obj);
}
Previous Question | Next Question |
How do you mark a method obsolete? | How do you directly call a native function exported from a DLL? |