ThreadStart Delegate
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Represents the method that executes on a Thread.
Assembly: mscorlib (in mscorlib.dll)
When a managed thread is created, the method that executes on the thread is represented by a ThreadStart delegate or a ParameterizedThreadStart delegate that is passed to the Thread constructor. The thread does not begin executing until the Thread::Start method is called. Execution begins at the first line of the method that is represented by the ThreadStart or ParameterizedThreadStart delegate.
Note: |
|---|
Visual Basic and C# users can omit the ThreadStart or ParameterizedThreadStart delegate constructor when creating a thread. In Visual Basic, use the AddressOf operator when passing your method to the Thread constructor; for example, Dim t As New Thread(AddressOf ThreadProc). In C#, just specify the name of the thread procedure. The compiler selects the correct delegate constructor. |
This section contains two examples. The first example shows how to use a ThreadStart delegate to execute a static method, and the second shows how to use a ThreadStart delegate to execute an instance method.
The examples display their output in a TextBlock on the UI thread. To access the TextBlock from the callback thread, the examples use the Dispatcher property to obtain a Dispatcher object for the TextBlock, and then use the Dispatcher::BeginInvoke method to make the cross-thread call.
For more information about thread creation, see Creating Threads and Passing Data at Start Time.
Example 1
The following code example shows how to use a ThreadStart delegate to execute a static method.
Example 2
The following code example shows how to use a ThreadStart delegate to execute an instance method.
Note: