Example

using System;
using System.Threading;
using System.Collections;

namespace Samples
{
  public class SynchronizationLockExceptionSample
  {
    private static Object o = new Object();
    public static void Main()
    {
      try
      {
        Monitor.Wait(o);
      }
      catch(SynchronizationLockException e)
      {
        Console.WriteLine("Exception: {0}", e);
      }
    }
  }
}
The output is
 Exception: System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code. at System.Threading.Monitor.ObjWait(Boolean exitContext, Int32 millisecondsTimeout, Object obj) at System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout, Boolean exitContext) at System.Threading.Monitor.Wait(Object obj) at Samples.SynchronizationLockExceptionSample.Main() ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.