mscorlib(4.0.0.0) API with additions
System.Threading.ThreadPool Class Reference

Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers. More...

Static Public Member Functions

static bool SetMaxThreads (int workerThreads, int completionPortThreads)
 Sets the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available. More...
 
static void GetMaxThreads (out int workerThreads, out int completionPortThreads)
 Retrieves the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available. More...
 
static bool SetMinThreads (int workerThreads, int completionPortThreads)
 Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction. More...
 
static void GetMinThreads (out int workerThreads, out int completionPortThreads)
 Retrieves the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction. More...
 
static void GetAvailableThreads (out int workerThreads, out int completionPortThreads)
 Retrieves the difference between the maximum number of thread pool threads returned by the M:System.Threading.ThreadPool.GetMaxThreads(System.Int32@,System.Int32@) method, and the number currently active. More...
 
static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned integer for the time-out in milliseconds. More...
 
static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread. More...
 
static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit signed integer for the time-out in milliseconds. More...
 
static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, using a 32-bit signed integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread. More...
 
static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 64-bit signed integer for the time-out in milliseconds. More...
 
static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 64-bit signed integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread. More...
 
static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a T:System.TimeSpan value for the time-out. More...
 
static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce)
 Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a T:System.TimeSpan value for the time-out. This method does not propagate the calling stack to the worker thread. More...
 
static bool QueueUserWorkItem (WaitCallback callBack, object state)
 Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available. More...
 
static bool QueueUserWorkItem (WaitCallback callBack)
 Queues a method for execution. The method executes when a thread pool thread becomes available. More...
 
static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
 Queues the specified delegate to the thread pool, but does not propagate the calling stack to the worker thread. More...
 
static unsafe bool UnsafeQueueNativeOverlapped (NativeOverlapped *overlapped)
 Queues an overlapped I/O operation for execution. More...
 
static bool BindHandle (IntPtr osHandle)
 Binds an operating system handle to the T:System.Threading.ThreadPool. More...
 
static bool BindHandle (SafeHandle osHandle)
 Binds an operating system handle to the T:System.Threading.ThreadPool. More...
 

Detailed Description

Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.

Definition at line 14 of file ThreadPool.cs.

Member Function Documentation

◆ BindHandle() [1/2]

static bool System.Threading.ThreadPool.BindHandle ( IntPtr  osHandle)
static

Binds an operating system handle to the T:System.Threading.ThreadPool.

Parameters
osHandleAn T:System.IntPtr that holds the handle. The handle must have been opened for overlapped I/O on the unmanaged side.
Returns
true if the handle is bound; otherwise, false.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 551 of file ThreadPool.cs.

◆ BindHandle() [2/2]

static bool System.Threading.ThreadPool.BindHandle ( SafeHandle  osHandle)
static

Binds an operating system handle to the T:System.Threading.ThreadPool.

Parameters
osHandleA T:System.Runtime.InteropServices.SafeHandle that holds the operating system handle. The handle must have been opened for overlapped I/O on the unmanaged side.
Returns
true if the handle is bound; otherwise, false.
Exceptions
T:System.ArgumentNullExceptionosHandle is null.

Definition at line 564 of file ThreadPool.cs.

◆ GetAvailableThreads()

static void System.Threading.ThreadPool.GetAvailableThreads ( out int  workerThreads,
out int  completionPortThreads 
)
static

Retrieves the difference between the maximum number of thread pool threads returned by the M:System.Threading.ThreadPool.GetMaxThreads(System.Int32@,System.Int32@) method, and the number currently active.

Parameters
workerThreadsThe number of available worker threads.
completionPortThreadsThe number of available asynchronous I/O threads.

Definition at line 65 of file ThreadPool.cs.

◆ GetMaxThreads()

static void System.Threading.ThreadPool.GetMaxThreads ( out int  workerThreads,
out int  completionPortThreads 
)
static

Retrieves the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available.

Parameters
workerThreadsThe maximum number of worker threads in the thread pool.
completionPortThreadsThe maximum number of asynchronous I/O threads in the thread pool.

Definition at line 32 of file ThreadPool.cs.

◆ GetMinThreads()

static void System.Threading.ThreadPool.GetMinThreads ( out int  workerThreads,
out int  completionPortThreads 
)
static

Retrieves the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction.

Parameters
workerThreadsWhen this method returns, contains the minimum number of worker threads that the thread pool creates on demand.
completionPortThreadsWhen this method returns, contains the minimum number of asynchronous I/O threads that the thread pool creates on demand.

Definition at line 56 of file ThreadPool.cs.

◆ QueueUserWorkItem() [1/2]

static bool System.Threading.ThreadPool.QueueUserWorkItem ( WaitCallback  callBack,
object  state 
)
static

Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.

Parameters
callBackA T:System.Threading.WaitCallback representing the method to execute.
stateAn object containing data to be used by the method.
Returns
true if the method is successfully queued; T:System.NotSupportedException is thrown if the work item could not be queued.
Exceptions
T:System.NotSupportedExceptionThe common language runtime (CLR) is hosted, and the host does not support this action.
T:System.ArgumentNullExceptioncallBack is null.

Definition at line 278 of file ThreadPool.cs.

◆ QueueUserWorkItem() [2/2]

static bool System.Threading.ThreadPool.QueueUserWorkItem ( WaitCallback  callBack)
static

Queues a method for execution. The method executes when a thread pool thread becomes available.

Parameters
callBackA T:System.Threading.WaitCallback that represents the method to be executed.
Returns
true if the method is successfully queued; T:System.NotSupportedException is thrown if the work item could not be queued.
Exceptions
T:System.ArgumentNullExceptioncallBack is null.
T:System.NotSupportedExceptionThe common language runtime (CLR) is hosted, and the host does not support this action.

Definition at line 294 of file ThreadPool.cs.

◆ RegisterWaitForSingleObject() [1/4]

static RegisteredWaitHandle System.Threading.ThreadPool.RegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
uint  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned integer for the time-out in milliseconds.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe T:System.Threading.WaitOrTimerCallback delegate to call when the waitObject parameter is signaled.
stateThe object passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle that can be used to cancel the registered wait operation.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe millisecondsTimeOutInterval parameter is less than -1.

Definition at line 82 of file ThreadPool.cs.

◆ RegisterWaitForSingleObject() [2/4]

static RegisteredWaitHandle System.Threading.ThreadPool.RegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
int  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit signed integer for the time-out in milliseconds.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe T:System.Threading.WaitOrTimerCallback delegate to call when the waitObject parameter is signaled.
stateThe object that is passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle that encapsulates the native handle.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe millisecondsTimeOutInterval parameter is less than -1.

Definition at line 137 of file ThreadPool.cs.

◆ RegisterWaitForSingleObject() [3/4]

static RegisteredWaitHandle System.Threading.ThreadPool.RegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
long  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 64-bit signed integer for the time-out in milliseconds.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe T:System.Threading.WaitOrTimerCallback delegate to call when the waitObject parameter is signaled.
stateThe object passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle that encapsulates the native handle.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe millisecondsTimeOutInterval parameter is less than -1.

Definition at line 180 of file ThreadPool.cs.

◆ RegisterWaitForSingleObject() [4/4]

static RegisteredWaitHandle System.Threading.ThreadPool.RegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
TimeSpan  timeout,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a T:System.TimeSpan value for the time-out.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe T:System.Threading.WaitOrTimerCallback delegate to call when the waitObject parameter is signaled.
stateThe object passed to the delegate.
timeoutThe time-out represented by a T:System.TimeSpan. If timeout is 0 (zero), the function tests the object's state and returns immediately. If timeout is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle that encapsulates the native handle.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe timeout parameter is less than -1.
T:System.NotSupportedExceptionThe timeout parameter is greater than F:System.Int32.MaxValue.

Definition at line 224 of file ThreadPool.cs.

◆ SetMaxThreads()

static bool System.Threading.ThreadPool.SetMaxThreads ( int  workerThreads,
int  completionPortThreads 
)
static

Sets the number of requests to the thread pool that can be active concurrently. All requests above that number remain queued until thread pool threads become available.

Parameters
workerThreadsThe maximum number of worker threads in the thread pool.
completionPortThreadsThe maximum number of asynchronous I/O threads in the thread pool.
Returns
true if the change is successful; otherwise, false.

Definition at line 23 of file ThreadPool.cs.

◆ SetMinThreads()

static bool System.Threading.ThreadPool.SetMinThreads ( int  workerThreads,
int  completionPortThreads 
)
static

Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction.

Parameters
workerThreadsThe minimum number of worker threads that the thread pool creates on demand.
completionPortThreadsThe minimum number of asynchronous I/O threads that the thread pool creates on demand.
Returns
true if the change is successful; otherwise, false.

Definition at line 45 of file ThreadPool.cs.

◆ UnsafeQueueNativeOverlapped()

static unsafe bool System.Threading.ThreadPool.UnsafeQueueNativeOverlapped ( NativeOverlapped overlapped)
static

Queues an overlapped I/O operation for execution.

Parameters
overlappedThe T:System.Threading.NativeOverlapped structure to queue.
Returns
true if the operation was successfully queued to an I/O completion port; otherwise, false.

Definition at line 473 of file ThreadPool.cs.

◆ UnsafeQueueUserWorkItem()

static bool System.Threading.ThreadPool.UnsafeQueueUserWorkItem ( WaitCallback  callBack,
object  state 
)
static

Queues the specified delegate to the thread pool, but does not propagate the calling stack to the worker thread.

Parameters
callBackA T:System.Threading.WaitCallback that represents the delegate to invoke when a thread in the thread pool picks up the work item.
stateThe object that is passed to the delegate when serviced from the thread pool.
Returns
true if the method succeeds; T:System.OutOfMemoryException is thrown if the work item could not be queued.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.
T:System.ApplicationExceptionAn out-of-memory condition was encountered.
T:System.OutOfMemoryExceptionThe work item could not be queued.
T:System.ArgumentNullExceptioncallBack is null.

Definition at line 312 of file ThreadPool.cs.

◆ UnsafeRegisterWaitForSingleObject() [1/4]

static RegisteredWaitHandle System.Threading.ThreadPool.UnsafeRegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
uint  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 32-bit unsigned integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe delegate to call when the waitObject parameter is signaled.
stateThe object that is passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle object that can be used to cancel the registered wait operation.
Exceptions
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 100 of file ThreadPool.cs.

◆ UnsafeRegisterWaitForSingleObject() [2/4]

static RegisteredWaitHandle System.Threading.ThreadPool.UnsafeRegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
int  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, using a 32-bit signed integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe delegate to call when the waitObject parameter is signaled.
stateThe object that is passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle object that can be used to cancel the registered wait operation.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe millisecondsTimeOutInterval parameter is less than -1.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 159 of file ThreadPool.cs.

◆ UnsafeRegisterWaitForSingleObject() [3/4]

static RegisteredWaitHandle System.Threading.ThreadPool.UnsafeRegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
long  millisecondsTimeOutInterval,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a 64-bit signed integer for the time-out in milliseconds. This method does not propagate the calling stack to the worker thread.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe delegate to call when the waitObject parameter is signaled.
stateThe object that is passed to the delegate.
millisecondsTimeOutIntervalThe time-out in milliseconds. If the millisecondsTimeOutInterval parameter is 0 (zero), the function tests the object's state and returns immediately. If millisecondsTimeOutInterval is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle object that can be used to cancel the registered wait operation.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe millisecondsTimeOutInterval parameter is less than -1.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 202 of file ThreadPool.cs.

◆ UnsafeRegisterWaitForSingleObject() [4/4]

static RegisteredWaitHandle System.Threading.ThreadPool.UnsafeRegisterWaitForSingleObject ( WaitHandle  waitObject,
WaitOrTimerCallback  callBack,
object  state,
TimeSpan  timeout,
bool  executeOnlyOnce 
)
static

Registers a delegate to wait for a T:System.Threading.WaitHandle, specifying a T:System.TimeSpan value for the time-out. This method does not propagate the calling stack to the worker thread.

Parameters
waitObjectThe T:System.Threading.WaitHandle to register. Use a T:System.Threading.WaitHandle other than T:System.Threading.Mutex.
callBackThe delegate to call when the waitObject parameter is signaled.
stateThe object that is passed to the delegate.
timeoutThe time-out represented by a T:System.TimeSpan. If timeout is 0 (zero), the function tests the object's state and returns immediately. If timeout is -1, the function's time-out interval never elapses.
executeOnlyOncetrue to indicate that the thread will no longer wait on the waitObject parameter after the delegate has been called; false to indicate that the timer is reset every time the wait operation completes until the wait is unregistered.
Returns
The T:System.Threading.RegisteredWaitHandle object that can be used to cancel the registered wait operation.
Exceptions
T:System.ArgumentOutOfRangeExceptionThe timeout parameter is less than -1.
T:System.NotSupportedExceptionThe timeout parameter is greater than F:System.Int32.MaxValue.
T:System.Security.SecurityExceptionThe caller does not have the required permission.

Definition at line 252 of file ThreadPool.cs.


The documentation for this class was generated from the following file: