Skip to content

Instantly share code, notes, and snippets.

@lomomike
Last active August 29, 2015 14:18
Show Gist options
  • Save lomomike/566d7e65a4ddfd4d26f5 to your computer and use it in GitHub Desktop.
Save lomomike/566d7e65a4ddfd4d26f5 to your computer and use it in GitHub Desktop.
Incorrect lock usage - SynchronizationLockException guarantee
class Program
{
private static object locker = new object();
static void Main(string[] args)
{
Monitor.Enter(locker);
Console.WriteLine("In Main Thread");
ThreadPool.QueueUserWorkItem((o) => {
Console.WriteLine("In New Thread");
Monitor.Exit(locker);
});
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment