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 that is passed to the Thread.Thread(ThreadStart) constructor. Any method that has no parameters and that returns void in C# or is a Sub procedure in Visual Basic can represent the delegate.
A Thread.Thread(ParameterizedThreadStart, Int32) constructor. Any method that has a single parameter of type Object and that returns void in C# or is a Sub procedure in Visual Basic can represent the delegate.delegate that is passed to the
The thread does not begin executing until the Thread.Start method is called. The ThreadStart or delegate is invoked on the thread, and execution begins at the first line of the method represented by the delegate. In the case of the delegate, the object that is passed to the Start(Object) method is passed to the delegate.
Visual Basic and C# users can omit the ThreadStart or 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.
When you create adelegate for an instance method in C++, the first parameter of the constructor is the instance variable. For a static method, the first parameter of the constructor is zero. For a static method, the delegate constructor requires only one parameter: the address of the callback method, qualified by the class name.
The Thread.Start(Object) method overload make it easy to pass data to a thread procedure, but this technique is not type safe because any object can be passed to Thread.Start(Object). A more robust way to pass data to a thread procedure is to put both the thread procedure and the data fields into a worker object. For more information, see Creating Threads and Passing Data at Start Time.delegate and the
Thedelegate supports only a single parameter. You can pass multiple data items to the by making that parameter one of the following:
The following code example uses a DoWork method and the second is represented by the instance DoMoreWork method. Both methods match the delegate signature; that is, they have a single parameter of type Object and don't return a value.delegate with to execute a static method and an instance method. The first delegate is represented by the static
The Visual Basic and C# compilers infer the DoWork and DoMoreWork methods, and call the correct constructor. Thus, there is no explicit constructor call in the code.delegate from the signatures of the
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0