public sealed class ThreadPool
|
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 ThreadPool.QueueUserWorkItem method. This method takes as a parameter a reference to the method or delegate 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 create an instance of the ThreadPool class. The thread pool has a default limit of 25 threads per available processor, which could be changed using CorSetMaxThreads as defined in the mscoree.h file. Each thread uses the default stack size and runs at the default priority. Each process can have only one operating system thread pool.
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetAvailableThreads | Retrieves the number of thread pool requests or work items that the user can add before reaching the maximum limit defined in ThreadPool.GetMaxThreads. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetMaxThreads | Retrieves the number of requests to the thread pool that can queue concurrently. All requests above that number are blocked until some of the queued requests finish work. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
QueueUserWorkItem | Overloaded:QueueUserWorkItem(WaitCallback callBack) Queues a user work item to the thread pool and invokes the specified delegate. |
QueueUserWorkItem | Overloaded:QueueUserWorkItem(WaitCallback callBack, object state) Queues a user work item to the thread pool, invokes the specified delegate, and specifies an object to be passed to the delegate when serviced from the thread pool. |
RegisterWaitForSingleObject | Overloaded:RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce) Registers a delegate that is waiting for a WaitHandle, using a 32-bit signed integer for the time out in milliseconds. |
RegisterWaitForSingleObject | Overloaded:RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce) Registers a delegate that is waiting for a WaitHandle, using a 32-bit unsigned integer for the time out in milliseconds. |
RegisterWaitForSingleObject | Overloaded:RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce) Registers a delegate that is waiting for a WaitHandle, using a TimeSpan value for the time out. |
RegisterWaitForSingleObject | Overloaded:RegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) Registers a delegate that is waiting for a WaitHandle, using a 32-bit unsigned integer for the time out in milliseconds. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
UnsafeQueueUserWorkItem | Queues a user work item to the thread pool. |
UnsafeRegisterWaitForSingleObject | Overloaded:UnsafeRegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce) Queues the specified delegate to the thread pool. |
UnsafeRegisterWaitForSingleObject | Overloaded:UnsafeRegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce) Queues the specified delegate to the thread pool. |
UnsafeRegisterWaitForSingleObject | Overloaded:UnsafeRegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce) Queues the specified delegate to the thread pool. |
UnsafeRegisterWaitForSingleObject | Overloaded:UnsafeRegisterWaitForSingleObject(WaitHandle waitObject, WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) Queues the specified delegate to the thread pool. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
~ThreadPool(); |
public static void GetAvailableThreads( |
workerThreads
completionPortThreads
public virtual int GetHashCode(); |
workerThreads
completionPortThreads
public Type GetType(); |
protected object MemberwiseClone(); |
public static bool QueueUserWorkItem( |
callBack
public static bool QueueUserWorkItem( |
callBack
state
public static RegisteredWaitHandle RegisterWaitForSingleObject( |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The millisecondsTimeOutInterval parameter is less than -1. |
public static RegisteredWaitHandle RegisterWaitForSingleObject( |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The millisecondsTimeOutInterval parameter is less than -1. |
public static RegisteredWaitHandle RegisterWaitForSingleObject( |
waitObject
callBack
state
timeout
executeOnlyOnce
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The timeout parameter is less than -1. |
NotSupportedException | The timeout parameter is greater than Int32.MaxValue. |
[CLSCompliant(false)] |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | The millisecondsTimeOutInterval parameter is less than -1. |
The RegisterWaitForSingleObject method checks the current state of the specified object's WaitHandle. If the object's state is non-signaled, the method registers a wait operation. The wait operation is performed by a thread from the thread pool. The delegate is executed by a worker thread when the object's state becomes signaled or the time-out interval elapses. If the timeOutInterval parameter is not zero (0) and the executeOnlyOnce parameter 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 RegisteredWaitHandle.Unregister method.
The wait thread uses the WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system 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 is decreased by one.
public virtual string ToString(); |
public static bool UnsafeQueueUserWorkItem( |
callBack
state
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( |
waitObject
callBack
state
timeout
executeOnlyOnce
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
[CLSCompliant(false)] |
waitObject
callBack
state
millisecondsTimeOutInterval
executeOnlyOnce
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |