mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00] 1.0.5000.0 2.0.0.0 4.0.0.0 Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details. System.Object

Many applications create threads that spend a great deal of time in the sleeping state, waiting for an event to occur. Other threads might enter a sleeping state only to be awakened periodically to poll for a change or update status information. The thread pool enables you to use threads more efficiently by providing your application with a pool of worker threads that are managed by the system. Examples of operations that use thread pool threads include the following:

When you create a or object to perform some task asynchronously, by default the task is scheduled to run on a thread pool thread.

Asynchronous timers use the thread pool. Thread pool threads execute callbacks from the class and raise events from the class.

When you use registered wait handles, a system thread monitors the status of the wait handles. When a wait operation completes, a worker thread from the thread pool executes the corresponding callback function.

The threads in the managed thread pool are background threads. That is, their properties are true. This means that a thread will not keep an application running after all foreground threads have exited.

When the thread pool reuses a thread, it does not clear the data in thread local storage or in fields that are marked with the attribute. Therefore, when a method examines thread local storage or fields that are marked with the attribute, the values it finds might be left over from an earlier use of the thread pool thread.

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 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.

There is one thread pool per process. Beginning with the net_v40_long, the default size of the thread pool for a process depends on several factors, such as the size of the virtual address space. A process can call the method to determine the number of threads. The number of threads in the thread pool can be changed by using the method. Each thread uses the default stack size and runs at the default priority.

Unmanaged code that hosts the .NET Framework can change the size of the thread pool by using the CorSetMaxThreads function, defined in the mscoree.h file.

The thread pool provides new worker threads or I/O completion threads on demand until it reaches the minimum for each category. When a minimum is reached, the thread pool can create additional threads in that category or wait until some tasks complete. Beginning with the net_v40_short, the thread pool creates and destroys worker threads in order to optimize throughput, which is defined as the number of tasks that complete per unit of time. Too few threads might not make optimal use of available resources, whereas too many threads could increase resource contention.

When demand is low, the actual number of thread pool threads can fall below the minimum values.

You can use the method to obtain these minimum values.

You can use the method to increase the minimum number of threads. However, unnecessarily increasing these values can cause performance problems. If too many tasks start at the same time, all of them might appear to be slow. In most cases the thread pool will perform better with its own algorithm for allocating threads.

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.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Obsolete("This method is obsolete, use BindHandle(SafeHandle) instead")
  System.Boolean `` To be added

  Binds an operating system handle to the .

  true if the handle is bound; otherwise, false.

  An that holds the handle. The handle must have been opened for overlapped I/O on the unmanaged side.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  The parameter should be a , which derives from the abstract class.

  Binds an operating system handle to the .

  true if the handle is bound; otherwise, false.

  A that holds the operating system handle. The handle must have been opened for overlapped I/O on the unmanaged side.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added: an object of type 'int&' To be added: an object of type 'int&' To be added To be added
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added: an object of type 'int&' To be added: an object of type 'int&' To be added To be added
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added. To be added. To be added. To be added.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  You can place data required by the queued method in the instance fields of the class in which the method is defined, or you can use the overload that accepts an object containing the necessary data.

  Visual Basic users can omit the constructor, and simply use the AddressOf operator when passing the callback method to . Visual Basic automatically calls the correct delegate constructor.

  ## Version Information

  In the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

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

  true if the method is successfully queued; is thrown if the work item could not be queued.

  A that represents the method to be executed.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  If the callback method requires complex data, you can define a class to contain the data.

  Visual Basic users can omit the constructor, and simply use the AddressOf operator when passing the callback method to . Visual Basic automatically calls the correct delegate constructor.

  ## Version Information

  In the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

  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.

  true if the method is successfully queued; is thrown if the work item could not be queued.

  A representing the method to execute. An object containing data to be used by the method.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

  The 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 method checks the current state of the specified object's . If the object's state is unsignaled, 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 parameter is not 0 (zero) and the parameter is false, the timer is reset every time the event is signaled or the time-out interval elapses.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread. Instead of a , use a with a maximum count of 1.

  To cancel the wait operation, call the method.

  The wait thread uses the Win32 WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system handle in multiple calls to , you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to , 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.

  ## Version Information

  Starting with the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

  Registers a delegate to wait for a , specifying a 32-bit signed integer for the time-out in milliseconds.

  The that encapsulates the native handle.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object that is passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

  The 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 method checks the current state of the specified object's . If the object's state is unsignaled, 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 parameter is not 0 (zero) and the parameter is false, the timer is reset every time the event is signaled or the time-out interval elapses.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread. Instead of a , use a with a maximum count of 1.

  To cancel the wait operation, call the method.

  The wait thread uses the Win32 WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system handle in multiple calls to , you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to , 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.

  ## Version Information

  Starting with the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

  Registers a delegate to wait for a , specifying a 64-bit signed integer for the time-out in milliseconds.

  The that encapsulates the native handle.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

  The 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 method checks the current state of the specified object's . If the object's state is unsignaled, 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 parameter is not 0 (zero) and the parameter is false, the timer is reset every time the event is signaled or the time-out interval elapses.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread. Instead of a , use a with a maximum count of 1.

  To cancel the wait operation, call the method.

  The wait thread uses the Win32 WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system handle in multiple calls to , you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to , 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.

  ## Version Information

  Starting with the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

  Registers a delegate to wait for a , specifying a value for the time-out.

  The that encapsulates the native handle.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object passed to the delegate. The time-out represented by a . If is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

  The 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 method checks the current state of the specified object's . If the object's state is unsignaled, 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 parameter is not 0 (zero) and the parameter is false, the timer is reset every time the event is signaled or the time-out interval elapses.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread. Instead of a , use a with a maximum count of 1.

  To cancel the wait operation, call the method.

  The wait thread uses the Win32 WaitForMultipleObjects function to monitor registered wait operations. Therefore, if you must use the same native operating system handle in multiple calls to , you must duplicate the handle using the Win32 DuplicateHandle function. Note that you should not pulse an event object passed to , 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.

  ## Version Information

  Starting with the .NET Framework version 2.0, the property value is propagated to worker threads queued using the method. In earlier versions, the principal information is not propagated.

  Registers a delegate to wait for a , specifying a 32-bit unsigned integer for the time-out in milliseconds.

  The that can be used to cancel the registered wait operation.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  You cannot set the number of worker threads or the number of I/O completion threads to a number smaller than the number of processors in the computer.

  If the common language runtime is hosted, for example by Internet Information Services (IIS) or SQL Server, the host can limit or prevent changes to the thread pool size.

  Use caution when changing the maximum number of threads in the thread pool. While your code might benefit, the changes might have an adverse effect on code libraries you use.

  Setting the thread pool size too large can cause performance problems. If too many threads are executing at the same time, the task switching overhead becomes a significant factor.

  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.

  true if the change is successful; otherwise, false.

  The maximum number of worker threads in the thread pool. The maximum number of asynchronous I/O threads in the thread pool.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  The thread pool provides new worker threads or I/O completion threads on demand until it reaches the minimum for each category. When the minimum is reached, the thread pool can create additional threads in that category or wait until some tasks complete. Beginning with the net_v40_short, the thread pool creates and destroys threads in order to optimize throughput, which is defined as the number of tasks that complete per unit of time. Too few threads might not make optimal use of available resources, whereas too many threads could increase resource contention.

  When demand is low, the actual number of thread pool threads can fall below the minimum values.

  If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using ), returns false and does not change either of the minimum values.

  You can use the method to increase the minimum number of threads. However, unnecessarily increasing these values can cause performance problems. If too many tasks start at the same time, all of them might appear to be slow. In most cases, the thread pool will perform better with its own algorithm for allocating threads. Reducing the minimum to less than the number of processors can also hurt performance.

  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.

  true if the change is successful; otherwise, false.

  The minimum number of worker threads that the thread pool creates on demand. The minimum number of asynchronous I/O threads that the thread pool creates on demand.
- Method
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Boolean ``

  For information about using native Win32 overlapped I/O, see the class, the structure, and the OVERLAPPED structure in the Win32 Platform SDK.

  Using the method could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread does not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

  Queues an overlapped I/O operation for execution.

  true if the operation was successfully queued to an I/O completion port; otherwise, false.

  The structure to queue.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean `` ``

  Unlike the method, does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

  Using could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

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

  true if the method succeeds; is thrown if the work item could not be queued.

  A that represents the delegate to invoke when a thread in the thread pool picks up the work item. The object that is passed to the delegate when serviced from the thread pool.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  Unlike the method, does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

  Using could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread.

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

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

  The object that can be used to cancel the registered wait operation.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object that is passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  Unlike the method, does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

  Using could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread.

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

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

  The object that can be used to cancel the registered wait operation.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object that is passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  Unlike the method, does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

  Using could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread.

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

  Registers a delegate to wait for a , specifying a value for the time-out. This method does not propagate the calling stack to the worker thread.

  The object that can be used to cancel the registered wait operation.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object that is passed to the delegate. The time-out represented by a . If is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.CLSCompliant(false)
  System.Threading.RegisteredWaitHandle `` `` `` `` ``

  Unlike the method, does not propagate the calling stack to the worker thread. This allows code to lose the calling stack and thereby to elevate its security privileges.

  Using could inadvertently open up a security hole. Code access security bases its permission checks on the permissions of all the callers on the stack. When work is queued on a thread pool thread using , the stack of the thread pool thread will not have the context of the actual callers. Malicious code might be able exploit this to avoid permission checks.

  Using a for does not provide mutual exclusion for the callbacks because the underlying Win32 API uses the default WT_EXECUTEDEFAULT flag, so each callback is dispatched on a separate thread pool thread.

  When you are finished using the that is returned by this method, call its method to release references to the wait handle. We recommend that you always call the method, even if you specify true for . Garbage collection works more efficiently if you call the method instead of depending on the registered wait handle's finalizer.

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

  The object that can be used to cancel the registered wait operation.

  The to register. Use a other than . The delegate to call when the parameter is signaled. The object that is passed to the delegate. The time-out in milliseconds. If the parameter is 0 (zero), the function tests the object's state and returns immediately. If is -1, the function's time-out interval never elapses. true to indicate that the thread will no longer wait on the 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.