NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Monitor Reference

public sealed class Monitor 
{
  public static void Enter(Object obj);
  public static void Exit(Object obj);
  public static bool TryEnter(Object obj);
  public static bool TryEnter(Object obj, int millisecondsTimeout);
  public static bool TryEnter(Object obj, TimeSpan timeout);
  public static bool Wait(Object obj, int millisecondsTimeout, bool exitContext);
  public static bool Wait(Object obj, TimeSpan timeout, bool exitContext);
  public static bool Wait(Object obj, int millisecondsTimeout);
  public static bool Wait(Object obj, TimeSpan timeout);
  public static bool Wait(Object obj, bool exitContext);
  public static bool Wait(Object obj);
  public static void Pulse(Object obj);
  public static void PulseAll(Object obj);
}

Enter

public static void Enter(Object obj);

Obtain the monitor lock of obj. Will block if another thread holds the lock. Will not block if the current thread holds the lock, however the caller must ensure that the same number of Exit calls are made as there were Enter calls.

Enter the Monitor within an object. An object is passed as a parameter. If object parameter is null a ArgumentNullException is thrown. This call will block if another thread has entered the Monitor of the same object. It will not block if the current thread has previously entered the Monitor, however the caller must ensure that the same number of Exit calls are made as there were Enter calls.

Thread.Interrupt can interrupt threads waiting to enter a Monitor on an object. A ThreadInterrupted exception will be thrown.

Exceptions: ArgumentNullException if object is null.

Exit

public static void Exit(Object obj);

Release the monitor lock. If one or more threads are waiting to acquire the lock, and the current thread has executed as many Exits as Enters, one of the threads will be unblocked and allowed to proceed.

Leave a Monitor. If one or more threads are waiting to enter the critical section, and the current thread has executed as many Exits as Enters, one of the threads will be unblocked and allowed to proceed.

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

Pulse

public static void Pulse(Object obj)

Sends a notification for a single waiting object

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

PulseAll

public static void PulseAll(Object obj)

Sends a notification to all waiting objects. SynchronizationLockException if this method is not called inside a synchronized block of code.

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

TryEnter

public static bool TryEnter(Object obj);

Similar to Enter, but will never block. That is, if the current thread can acquire the monitor lock without blocking, it will do so and TRUE will be returned. Otherwise FALSE will be returned.

Exceptions:

ArgumentNullException if object is null.

TryEnter

public static bool TryEnter(Object obj, int timeout)

Version of TryEnter that will block, but only up to a timeout period expressed in milliseconds. If timeout == Timeout.Infinite the method becomes equivalent to Enter.

Exceptions:

ArgumentNullException if object is null.

ArgumentException if timeout < 0.

Wait

public static bool Wait(Object obj);

Waits for notification from the object (via a Pulse/PulseAll).

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

Wait

public static bool Wait(Object obj, int millisecondsTimeout);

Waits for notification from the object (via a Pulse/PulseAll). millisecondsTimeout indicates how long to wait before the method returns.

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

Wait

public static bool Wait(Object obj, TimeSpan timeout);

Waits for notification from the object (via a Pulse/PulseAll). TimeSpan indicates how long to wait before the method returns.

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

Wait

public static bool Wait(Object obj, int millisecondsTimeout, bool exitContext);

Waits for notification from the object (via a Pulse/PulseAll). millisecondsTimeout indicates how long to wait before the method returns.

If exitContext is true then the synchronization domain for the context (if in a synchronized context) is exited before the wait and reacquired

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.

Wait

public static bool Wait(Object obj, TimeSpan timeout, bool exitContext);

Waits for notification from the object (via a Pulse/PulseAll). timeout indicates how long to wait before the method returns.

If exitContext is true then the synchronization domain for the context (if in a synchronized context) is exited before the wait and reacquired

Exceptions:

ArgumentNullException if object is null.

SynchronizationLockException if this method is not called inside a synchronized block of code.