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!

ThreadPool Methods

The methods of the ThreadPool class are listed below. For a complete list of ThreadPool class members, see the ThreadPool Members topic.

Public:

BindHandle Binds an OS handle to the ThreadPool.
Equals (inherited from Object) Determines whether the specified Object is the same instance as the current Object. Subclasses are expected to override this method to support value equality (not reference equality).
GetHashCode (inherited from Object) Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.
GetType (inherited from Object) Gets the Type of the Object.
QueueUserWorkItem Overloaded. Queues a user work item to the thread pool.

State data can be stored in the instance fields of the class on which the delegate is defined. By default, the callback function is queued to a non-I/O worker thread.

RegisterWaitForSingleObject Overloaded. Registers an object so that when the time-out occurs the delegate is called.

The RegisterWaitForSingleObject method queues the specified delegate to the thread pool. A worker thread will execute the delegate when one of the following occurs:

  • The specified object is in the signaled state.
  • The time-out interval elapses.

The RegisterWaitForSingleObject method checks the current state of the specified object WaitHandle. If the object's state is nonsignaled, the method registers a wait operation. The wait operation is performed by a thread from the system thread pool. The delegate is executed by a worker thread when the object's state becomes signaled or the time-out interval elapses. If timeOutInterval is not zero and executeOnlyOnce is not false, the timer is reset every time the event is signaled or the time-out interval elapses.

To cancel the wait operation, call the TBD method. Do not make a blocking System.Threading.RegisteredWaitHandle.Unregister call within the delegate.

The wait thread uses the WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native OS handle in multiple calls to RegisterWaitForSingleObject, you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to RegisterWaitForSingleObject, because the wait thread might not detect that the event is signaled before it is reset.

Before returning, the function modifies the state of some types of synchronization objects. Modification occurs only for the object whose signaled state caused the wait condition to be satisfied. For example, the count of a semaphore object is decreased by one.

The RegisterWaitForSingleObject method can wait for the following objects:

  • Change notification
  • Console input
  • Event
  • Job
  • Mutex
  • Process
  • Semaphore
  • Thread
  • Waitable timer
ToString (inherited from Object) Protected:

Finalize (inherited from Object)

Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by the Garbage Collector (GC). This method may be ignored by the runtime; therefore, necessary cleanup operations should be done elsewhere.

MemberwiseClone (inherited from Object)

Creates a shallow copy of the current Object.

.

See Also

ThreadPool Class | System.Threading Namespace