using System; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Runtime.Remoting.Contexts; namespace System.Threading { /// Provides a mechanism that synchronizes access to objects. /// 2 // Token: 0x02000615 RID: 1557 [ComVisible(true)] public static class Monitor { // Token: 0x060038D9 RID: 14553 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Monitor_try_enter(object obj, int ms); /// Acquires an exclusive lock on the specified object. /// The object on which to acquire the monitor lock. /// The parameter is null. /// 1 // Token: 0x060038DA RID: 14554 [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Enter(object obj); /// Releases an exclusive lock on the specified object. /// The object on which to release the lock. /// The parameter is null. /// The current thread does not own the lock for the specified object. /// 1 // Token: 0x060038DB RID: 14555 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Exit(object obj); // Token: 0x060038DC RID: 14556 [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Monitor_pulse(object obj); // Token: 0x060038DD RID: 14557 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Monitor_test_synchronised(object obj); /// Notifies a thread in the waiting queue of a change in the locked object's state. /// The object a thread is waiting for. /// The parameter is null. /// The calling thread does not own the lock for the specified object. /// 1 // Token: 0x060038DE RID: 14558 RVA: 0x000C4514 File Offset: 0x000C2714 public static void Pulse(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } if (!Monitor.Monitor_test_synchronised(obj)) { throw new SynchronizationLockException("Object is not synchronized"); } Monitor.Monitor_pulse(obj); } // Token: 0x060038DF RID: 14559 [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Monitor_pulse_all(object obj); /// Notifies all waiting threads of a change in the object's state. /// The object that sends the pulse. /// The parameter is null. /// The calling thread does not own the lock for the specified object. /// 1 // Token: 0x060038E0 RID: 14560 RVA: 0x000C4544 File Offset: 0x000C2744 public static void PulseAll(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } if (!Monitor.Monitor_test_synchronised(obj)) { throw new SynchronizationLockException("Object is not synchronized"); } Monitor.Monitor_pulse_all(obj); } /// Attempts to acquire an exclusive lock on the specified object. /// true if the current thread acquires the lock; otherwise, false. /// The object on which to acquire the lock. /// The parameter is null. /// 1 // Token: 0x060038E1 RID: 14561 RVA: 0x000C4574 File Offset: 0x000C2774 public static bool TryEnter(object obj) { return Monitor.TryEnter(obj, 0); } /// Attempts, for the specified number of milliseconds, to acquire an exclusive lock on the specified object. /// true if the current thread acquires the lock; otherwise, false. /// The object on which to acquire the lock. /// The number of milliseconds to wait for the lock. /// The parameter is null. /// /// is negative, and not equal to . /// 1 // Token: 0x060038E2 RID: 14562 RVA: 0x000C4580 File Offset: 0x000C2780 public static bool TryEnter(object obj, int millisecondsTimeout) { if (obj == null) { throw new ArgumentNullException("obj"); } if (millisecondsTimeout == -1) { Monitor.Enter(obj); return true; } if (millisecondsTimeout < 0) { throw new ArgumentException("negative value for millisecondsTimeout", "millisecondsTimeout"); } return Monitor.Monitor_try_enter(obj, millisecondsTimeout); } /// Attempts, for the specified amount of time, to acquire an exclusive lock on the specified object. /// true if the current thread acquires the lock without blocking; otherwise, false. /// The object on which to acquire the lock. /// A representing the amount of time to wait for the lock. A value of –1 millisecond specifies an infinite wait. /// The parameter is null. /// The value of in milliseconds is negative and is not equal to (–1 millisecond), or is greater than . /// 1 // Token: 0x060038E3 RID: 14563 RVA: 0x000C45CC File Offset: 0x000C27CC public static bool TryEnter(object obj, TimeSpan timeout) { long num = (long)timeout.TotalMilliseconds; if (num < -1L || num > 2147483647L) { throw new ArgumentOutOfRangeException("timeout", "timeout out of range"); } return Monitor.TryEnter(obj, (int)num); } // Token: 0x060038E4 RID: 14564 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Monitor_wait(object obj, int ms); /// Releases the lock on an object and blocks the current thread until it reacquires the lock. /// true if the call returned because the caller reacquired the lock for the specified object. This method does not return if the lock is not reacquired. /// The object on which to wait. /// The parameter is null. /// The calling thread does not own the lock for the specified object. /// The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's method. /// 1 // Token: 0x060038E5 RID: 14565 RVA: 0x000C4610 File Offset: 0x000C2810 public static bool Wait(object obj) { return Monitor.Wait(obj, -1); } /// Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. /// true if the lock was reacquired before the specified time elapsed; false if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. /// The object on which to wait. /// The number of milliseconds to wait before the thread enters the ready queue. /// The parameter is null. /// The calling thread does not own the lock for the specified object. /// The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's method. /// The value of the parameter is negative, and is not equal to . /// 1 // Token: 0x060038E6 RID: 14566 RVA: 0x000C461C File Offset: 0x000C281C public static bool Wait(object obj, int millisecondsTimeout) { if (obj == null) { throw new ArgumentNullException("obj"); } if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException("millisecondsTimeout", "timeout out of range"); } if (!Monitor.Monitor_test_synchronised(obj)) { throw new SynchronizationLockException("Object is not synchronized"); } return Monitor.Monitor_wait(obj, millisecondsTimeout); } /// Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. /// true if the lock was reacquired before the specified time elapsed; false if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. /// The object on which to wait. /// A representing the amount of time to wait before the thread enters the ready queue. /// The parameter is null. /// The calling thread does not own the lock for the specified object. /// The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's method. /// The value of the parameter in milliseconds is negative and does not represent (–1 millisecond), or is greater than . /// 1 // Token: 0x060038E7 RID: 14567 RVA: 0x000C4670 File Offset: 0x000C2870 public static bool Wait(object obj, TimeSpan timeout) { long num = (long)timeout.TotalMilliseconds; if (num < -1L || num > 2147483647L) { throw new ArgumentOutOfRangeException("timeout", "timeout out of range"); } return Monitor.Wait(obj, (int)num); } /// Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. This method also specifies whether the synchronization domain for the context (if in a synchronized context) is exited before the wait and reacquired afterward. /// true if the lock was reacquired before the specified time elapsed; false if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. /// The object on which to wait. /// The number of milliseconds to wait before the thread enters the ready queue. /// true to exit and reacquire the synchronization domain for the context (if in a synchronized context) before the wait; otherwise, false. /// The parameter is null. /// Wait is not invoked from within a synchronized block of code. /// The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's method. /// The value of the parameter is negative, and is not equal to . /// 1 // Token: 0x060038E8 RID: 14568 RVA: 0x000C46B4 File Offset: 0x000C28B4 public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { bool flag; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } flag = Monitor.Wait(obj, millisecondsTimeout); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } return flag; } /// Releases the lock on an object and blocks the current thread until it reacquires the lock. If the specified time-out interval elapses, the thread enters the ready queue. Optionally exits the synchronization domain for the synchronized context before the wait and reacquires the domain afterward. /// true if the lock was reacquired before the specified time elapsed; false if the lock was reacquired after the specified time elapsed. The method does not return until the lock is reacquired. /// The object on which to wait. /// A representing the amount of time to wait before the thread enters the ready queue. /// true to exit and reacquire the synchronization domain for the context (if in a synchronized context) before the wait; otherwise, false. /// The parameter is null. /// Wait is not invoked from within a synchronized block of code. /// The thread that invokes Wait is later interrupted from the waiting state. This happens when another thread calls this thread's method. /// The parameter is negative and does not represent (–1 millisecond), or is greater than . /// 1 // Token: 0x060038E9 RID: 14569 RVA: 0x000C4708 File Offset: 0x000C2908 public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { bool flag; try { if (exitContext) { SynchronizationAttribute.ExitContext(); } flag = Monitor.Wait(obj, timeout); } finally { if (exitContext) { SynchronizationAttribute.EnterContext(); } } return flag; } } }