Initializes a new instance of the Thread class.
Namespace:
System.Threading
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Public Sub New ( _
start As ThreadStart _
)
Dim start As ThreadStart
Dim instance As New Thread(start)
public Thread(
ThreadStart start
)
public:
Thread(
ThreadStart^ start
)
public function Thread(
start : ThreadStart
)
| Exception | Condition |
|---|
| ArgumentNullException | The start parameter is nullNothingnullptra null reference (Nothing in Visual Basic). |
A thread does not begin executing when it is created. To schedule the thread for execution, call the Start method.
vb# Note: |
|---|
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.
Imports System
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
Dim newThread As New Thread(AddressOf Work.DoWork)
newThread.Start()
End Sub
End Class
Public Class Work
Private Sub New()
End Sub
Shared Sub DoWork()
End Sub
End Class
using System;
using System.Threading;
class Test
{
static void Main()
{
Thread newThread =
new Thread(new ThreadStart(Work.DoWork));
newThread.Start();
}
}
class Work
{
Work() {}
public static void DoWork() {}
}
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.
Imports System
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
Dim threadWork As New Work()
Dim newThread As New Thread(AddressOf threadWork.DoWork)
newThread.Start()
End Sub
End Class
Public Class Work
Sub New()
End Sub
Sub DoWork()
End Sub
End Class
using System;
using System.Threading;
class Test
{
static void Main()
{
Work threadWork = new Work();
Thread newThread =
new Thread(new ThreadStart(threadWork.DoWork));
newThread.Start();
}
}
class Work
{
public Work() {}
public void DoWork() {}
}
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();
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference
Other Resources