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!

System.Threading Namespace

Classes

Class Description
AutoResetEvent An AutoResetEvent is automatically reset to nonsignaled by the system after a single waiting thread has been released. The state of an auto-reset event object remains signaled until a single waiting thread is released, at which time the system automatically sets the state to nonsignaled. If no threads are waiting, the event object's state remains signaled.
Interlocked The Interlocked class provides the mechanism for synchronizing access to a variable that is shared by multiple threads. The threads of different processes can use this mechanism if the variable is in shared memory.
ManualResetEvent Represents an event object whose state can be manually set and reset. The state of a manual-reset event object remains signaled until it is set explicitly to the nonsignaled state by the Reset method. Any number of waiting threads, or threads that subsequently begin wait operations for the specified event object by calling one of the wait functions, can be released while the object's state is signaled.
Monitor
  • Associated with an object on demand.
  • Are unbound, i.e., can be called directly from any Context.
  • Can not be instanciated. (They are associated with an object)
Mutex A synchronization primitive than can also be used for interprocess synchronization.

Wait can be used to request ownership of the mutex. The state of the mutex is signaled if no thread owns it.

The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. It must release the mutex as many times to release ownership.

If a thread terminates normally while owning a mutex, the state of the mutex is set to signaled and the next waiting thread gets ownership.

Overlapped Used to pack and unpack the managed overlapped to and from the native overlapped.
ReaderWriterLock Defines the lock that implements single-writer/ multiple-reader semantics that supports the following features:
  • Cheap enough to be used in large numbers such as per object synchronization.
  • Supports timeout. This is a valuable feature to detect deadlocks.
  • Supports caching of events. This allows the events to be moved from least contentious regions to the most contentious regions. In other words, the number of events needed by Reader-Writer locks is bounded by the number of threads in the process.
  • Supports nested locks by readers and writers.
  • Supports spin counts for avoiding context switches on multi processor machines.
  • Supports functionality for upgrading to a writer lock with a return argument that indicates intermediate writes. Downgrading from a writer lock restores the state of the lock.
  • Supports functionality to Release Lock for calling app code. RestoreLock restores the lock state and indicates intermediate writes.
  • Recovers from most common failures such as creation of events. In other words, the lock maintains consistent internal state and remains usable.

Timeout is in milliseconds:

RegisteredWaitHandle Represents a handle that has been registered when calling TBD.
SynchronizationLockException Represents the exception that is thrown if an object synchronization method is invoked from an unsynchronized block of code.
Thread Represents threads that execute within the runtime, to create and control threads.
ThreadAbortException Represents an exception that causes the thread to abort.
ThreadExceptionEventArgs Provides data for the System.WinForms.Application.OnThreadException event.
ThreadInterruptedException Represents an exception that is thrown when a thread is interrupted during the waiting state.
ThreadPool Posts work items to the thread pool.

Queue work items for execution on the first available thread from the thread pool.

One OS thread pool per process.

Efficient use of thread resources.

ThreadStateException Represents an exception that is thrown when a Thread is in an invalid state for the method call.
ThreadStopException Represents an exception that is thrown into a thread to cause it to stop.
Timeout Contains time-out values for the system.
Timer Specifies a delegate to be called at a specified time.

The wait operation is performed by a thread in the thread pool.

WaitHandle Represents all synchronization objects (that allow multiple wait) in the runtime.

Structures

Structure Description
LockCookie Defines the lock that implements single-writer/multiple-reader semantics. This is a value type.
NativeOverlapped Has an explicit layout that is visible from unmanaged code and will have the same layout as the Win32 OVERLAPPED structure with additional reserved field at the end.

Delegates

Delegate Description
IOCompletionCallback [To be supplied.]
ThreadExceptionEventHandler Represents the method that will handle the System.WinForms.Application.OnThreadException event of a Thread.OnThreadException.
ThreadStart The ThreadStart class is a delegate that points to the method that should be executed first when a thread is started.

Every subclass of Delegate and MulticastDelegate has a constructor and an Invoke method. See the example in the Delegate topic.

TimerCallback Delegate for the Timers.

Every subclass of Delegate and MulticastDelegate has a constructor and an Invoke method. See the Managed C++ code example given in the description for the Delegate class.

WaitCallback This class is a Delegate which defines the callback method for threadpool user work items. That method must match this delegate.

Every subclass of Delegate and MulticastDelegate has a constructor and an Invoke method. See the Managed C++ code example given in the description for the Delegate class.

WaitOrTimerCallback Delegate for the registered Wait objects.

Receives a boolean parameter wich determines whether the handle was signaled or the WaitHandle timed out.

Enumerations

Enumeration Description
ApartmentState Represents the appartment state of a Thread.
ThreadPriority Specifies the priority of the thread.
ThreadState Specifies the state of a thread.

A thread can be in multiple states at the same time. The property ThreadState provides a bit mask indicating the thread's current state. A thread is always in at least one of these possible states in the ThreadState enumeration.