This documentation is archived and is not being maintained.

ThreadStart Delegate

Represents the method that executes on a Thread.

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

<ComVisibleAttribute(True)> _
Public Delegate Sub ThreadStart ()
Dim instance As New ThreadStart(AddressOf HandlerMethod)
/** @delegate */
/** @attribute ComVisibleAttribute(true) */ 
public delegate void ThreadStart ()
JScript supports the use of delegates, but not the declaration of new ones.

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 System.Threading.Thread.Start method is called. Execution begins at the first line of the method represented by the ThreadStart or ParameterizedThreadStart delegate.


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#, simply specify the name of the thread procedure. The compiler selects the correct delegate constructor.


In version 2.0 of the .NET Framework, creating a ThreadStart delegate for a static method in C++ requires only one parameter: the address of the callback method, qualified by the class name. In earlier versions two parameters were required when creating a delegate for a static method: zero (null) and the method address. For an instance method, all versions require two parameters: the instance variable and the method address.

The following code example shows the syntax for creating and using a ThreadStart delegate with an instance method and with a static method.

For another simple example that demonstrates how to create a ThreadStart delegate, see the Thread.Start method overload. For more information about thread creation, see Creating Threads and Passing Data at Start Time.

Imports System
Imports System.Threading

Public Class Test

    <MTAThread> _
    Shared Sub Main()
        ' To start a thread using a static thread procedure, use the
        ' class name and method name when you create the ThreadStart
        ' delegate. Visual Basic expands the AddressOf expression 
        ' to the appropriate delegate creation syntax:
        '    New ThreadStart(AddressOf Work.DoWork)
        Dim newThread As New Thread(AddressOf Work.DoWork)

        ' To start a thread using an instance method for the thread 
        ' procedure, use the instance variable and method name when 
        ' you create the ThreadStart delegate. Visual Basic expands 
        ' the AddressOf expression to the appropriate delegate 
        ' creation syntax:
        '    New ThreadStart(AddressOf w.DoMoreWork)
        Dim w As New Work()
        w.Data = 42
        newThread = new Thread(AddressOf w.DoMoreWork)
    End Sub
End Class

Public Class Work 
    Public Shared Sub DoWork()
        Console.WriteLine("Static thread procedure.")
    End Sub
    Public Data As Integer
    Public Sub DoMoreWork() 
        Console.WriteLine("Instance thread procedure. Data={0}", Data) 
    End Sub
End Class

' This code example produces the following output (the order 
'   of the lines might vary):
'Static thread procedure.
'Instance thread procedure. Data=42

import System.*;
import System.Threading.*;
import System.Threading.Thread;

class Test
    public static void main(String[] args)
        ThreadStart threadDelegate = new ThreadStart(Work.DoWork);
        Thread newThread = new Thread(threadDelegate);
    } //main
} //Test

class Work
    public static void DoWork()
    } //DoWork
} //Work

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0