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 Class

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.

Object
   ThreadPool

[Visual Basic]
NotInheritable Public Class ThreadPool
[C#]
public sealed class ThreadPool
[C++]
public __gc __sealed class ThreadPool
[JScript]
public class ThreadPool

Remarks

There are many applications that create threads that spend a great deal of time in the sleeping state waiting for an event to occur. Other threads may enter a sleeping state only to be awakened periodically to poll for a change or update status information.

Thread pooling enables you to use threads more efficiently by providing your application with a pool of worker threads that are managed by the system. One thread monitors the status of all wait operations queued to the thread pool. When a wait operation has completed, a worker thread from the thread pool executes the corresponding callback function.

You can also queue work items that are not related to a wait operation to the thread pool. To request that a work item be handled by a thread in the thread pool, call the CorQueueUserWorkItem or System.ThreadPool.QueueUserWorkItem functions. This function takes a parameter to the function or delegate respectively, that will be called by the thread selected from the thread pool. There is no way to cancel a work item after it has been queued.

Timer-queue timers and registered wait operations also use the thread pool. Their callback functions are queued to the thread pool.

The thread pool is created the first time you call QueueUserWorkItem, or when a timer-queue timer or registered wait operation queues a callback function. The number of threads that can be created in the thread pool is limited only by available memory. Each thread uses the default stack size and runs at the default priority. Each thread can handle up to 63 wait operations.

Restrictions

Disallow ability to queue callbacks as an APC on the wait thread.

Disallow specification of a long computation.

Requirements

Namespace: System.Threading

Assembly: mscorlib.dll

See Also

ThreadPool Members | System.Threading Namespace