ThreadPool.QueueUserWorkItem Method (WaitCallback, Object)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

static member QueueUserWorkItem : 
        callBack:WaitCallback *
        state:Object -> bool


Type: System.Threading.WaitCallback

A WaitCallback representing the method to execute.

Type: System.Object

An object containing data to be used by the method.

Return Value

Type: System.Boolean

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

Exception Condition

The common language runtime (CLR) is hosted, and the host does not support this action.


callBack is null.

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


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

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

The following example shows how to create an object that contains task information. It also demonstrates how to pass that object to a task that is queued for execution by the thread pool.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top