Windows apps
Collapse the table of content
Expand the table of content
Information
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.

Thread Constructor (ThreadStart^)

 

Initializes a new instance of the Thread class.

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

public:
Thread(
	ThreadStart^ start
)

Parameters

start
Type: System.Threading::ThreadStart^

A ThreadStart delegate that represents the methods to be invoked when this thread begins executing.

Exception Condition
ArgumentNullException

The start parameter is null.

A thread does not begin executing when it is created. To schedule the thread for execution, call the Start method.

System_CAPS_noteNote

Visual Basic users can omit the ThreadStart constructor when creating a thread. Use the AddressOf operator when passing your method for example Dim t As New Thread(AddressOf ThreadProc). Visual Basic automatically calls the ThreadStart constructor.

The following code example shows how to create a thread that executes a static method.

using namespace System;
using namespace System::Threading;
ref class Work
{
private:
   Work(){}


public:
   static void DoWork(){}

};

int main()
{
   Thread^ newThread = gcnew Thread( gcnew ThreadStart( &Work::DoWork ) );
   newThread->Start();
}

The following code example shows how to create a thread that executes an instance method.

using namespace System;
using namespace System::Threading;
ref class Work
{
public:
   Work(){}

   void DoWork(){}

};

int main()
{
   Work^ threadWork = gcnew Work;
   Thread^ newThread = gcnew Thread( gcnew ThreadStart( threadWork, &Work::DoWork ) );
   newThread->Start();
}

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2017 Microsoft