System.Threading.ThreadPool.QueueUserWorkItem Method

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.

Syntax

public static bool QueueUserWorkItem (WaitCallback callBack, object state)

Parameters

callBack
A System.Threading.WaitCallback representing the method to execute.
state
An object containing data to be used by the method.

Returns

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

Remarks

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

Note:

Visual Basic users can omit the System.Threading.WaitCallback constructor, and simply use the AddressOf operator when passing the callback method to ThreadPool.QueueUserWorkItem(WaitCallback, object). Visual Basic automatically calls the correct delegate constructor.

Version Information

In the .NET Framework version 2.0, the Thread.CurrentPrincipal property value is propagated to worker threads queued using the erload:System.Threading.ThreadPool.QueueUserWorkItem method. In earlier versions, the principal information is not propagated.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0