The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ThreadPool.QueueUserWorkItem Method (WaitCallback)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

public static bool QueueUserWorkItem(
	WaitCallback callBack


Type: System.Threading.WaitCallback
The method to execute.

Return Value

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


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


callBack is null.

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 QueueUserWorkItem(WaitCallback, Object) overload that accepts an object containing the necessary data.


Visual Basic and C# users can omit the WaitCallback delegate constructor when specifying the callback method in calls to the QueueUserWorkItem method. In Visual Basic, use the AddressOf operator. The compilers automatically call the correct delegate constructor.

The following example uses the QueueUserWorkItem(WaitCallback) method overload to queue a task, which is represented by the ThreadProc method, to execute when a thread becomes available. No task information is supplied with this overload. Therefore, the information that is available to the ThreadProc method is limited to the object the method belongs to.

The example displays its output in a TextBlock on the UI thread. To access the TextBlock from the callback thread, the example uses the Dispatcher property to obtain a Dispatcher object for the TextBlock, and then uses the Dispatcher.BeginInvoke method to make the cross-thread call.

using System;
using System.Threading;

class Example
    // This is the UI element that receives the output from the example.
    private static System.Windows.Controls.TextBlock outputBlock;

    // The Demo method runs the example. It saves the TextBlock that is 
    // used for output, and sets up an event handler to start tasks.
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
        Example.outputBlock = outputBlock;
        outputBlock.Text = "Click here to start a background task.\r\n";

        // Set up an event handler to start a task when the TextBlock 
        // is clicked.
        outputBlock.MouseLeftButtonUp += HandleMouseUp;

    // Clicking the TextBlock queues a delegate to perform a task on a 
    // thread pool thread.
    private static void HandleMouseUp(object sender, 
                                      System.Windows.Input.MouseButtonEventArgs e)

        // Note: The stateInfo object for the task in this example is
        // Nothing, because this overload of QueueUserWorkItem does not
        // take a stateInfo parameter. 

    // This method performs the task, which is to append text to the
    // TextBlock. To communicate with objects on the UI thread, get the 
    // Dispatcher for one of the UI objects. Use the Dispatcher object's 
    // BeginInvoke method to queue a delegate that will run on the UI thread,
    // and therefore can safely access UI elements like the TextBlock.
    private static void AppendTextTask(object stateInfo)
        outputBlock.Dispatcher.BeginInvoke(delegate () {
            outputBlock.Text += "Hello from the thread pool.\r\n";

/* This code produces output similar to the following:

Click here to start a background task.
Hello from the thread pool.
Hello from the thread pool.
Hello from the thread pool.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone