The lock
keyword is just syntactic sugar for Monitor.Enter and Monitor.Exit:
Monitor.Enter(o);
try
{
//put your code here
}
finally
{
Monitor.Exit(o);
}
is the same as
lock(o)
{
//put your code here
}
More Related Contents:
- Why is lock(this) {…} bad?
- Volatile vs. Interlocked vs. lock
- Concurrent HashSet in .NET Framework?
- Asynchronous locking based on a key
- Re-entrant locks in C#
- Is Task.Factory.StartNew() guaranteed to use another thread than the calling thread?
- Is it OK to use a string as a lock object?
- Does a locked object stay locked if an exception occurs inside it?
- How expensive is the lock statement?
- Monitor vs lock
- lock keyword in C#
- What are the differences between various threading synchronization options in C#?
- Do I need to lock or mark as volatile when accessing a simple boolean flag in C#?
- Throw a NullReferenceException while calling the set_item method of a Dictionary object in a multi-threading scenario
- Why does the lock object have to be static?
- When is ReaderWriterLockSlim better than a simple lock?
- Cross-Process Locking in C#
- Why is it a bad practice to lock the object we are going to change?
- Guidelines of when to use locking
- What’s wrong with using Thread.Abort()
- Change WPF controls from a non-main thread using Dispatcher.Invoke
- How to kill a thread instantly in C#?
- Updating an ObservableCollection in a separate thread
- How to catch exceptions from a ThreadPool.QueueUserWorkItem?
- WPF UI multitasking
- What is the difference between ManualResetEvent and AutoResetEvent in .NET?
- Lock (Monitor) internal implementation in .NET
- .NET 4.0 and the dreaded OnUserPreferenceChanged Hang
- SynchronizationLockException on Monitor.Exit when using await
- How to handle Task.Run Exception