Causes the operating system to change the state of the current instance to ThreadState
Assembly: mscorlib (in mscorlib.dll)
<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization := True, _
ExternalThreading := True)> _
Public Sub Start[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true,
ExternalThreading = true)]
public void Start()[HostProtectionAttribute(SecurityAction::LinkDemand, Synchronization = true,
ExternalThreading = true)]
public:
void Start()[<HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true,
ExternalThreading = true)>]
member Start : unit -> unit
| Exception | Condition |
|---|---|
| ThreadStateException | The thread has already been started. |
| OutOfMemoryException | There is not enough memory available to start this thread. |
Once a thread is in the ThreadState
Note |
|---|
If this overload is used with a thread created using a ParameterizedThreadStart delegate, |
Once the thread terminates, it cannot be restarted with another call to Start.
Note |
|---|
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes. |
The following code example demonstrates creating a thread and starting it.
This code produces the following output:
In main.
Working thread...
In main. Working thread...
In main.
Working thread...Note that the sequence of the output statements is typical, but is not guaranteed to be identical across systems.
Thread procedures can be static methods or instance methods. See the code example provided for the ThreadStart delegate. For more information about thread creation, see Creating Threads and Passing Data at Start Time.
Imports System
Imports System.Threading
Public Class ThreadWork
Public Shared Sub DoWork()
Dim i As Integer
For i = 0 To 2
Console.WriteLine("Working thread...")
Thread.Sleep(100)
Next i
End Sub 'DoWork
End Class 'ThreadWork
Class ThreadTest
Public Shared Sub Main()
Dim myThreadDelegate As New ThreadStart(AddressOf ThreadWork.DoWork)
Dim myThread As New Thread(myThreadDelegate)
myThread.Start()
Dim i As Integer
For i = 0 To 2
Console.WriteLine("In main.")
Thread.Sleep(100)
Next i
End Sub 'Main
End Class 'ThreadTest
using System;
using System.Threading;
public class ThreadWork
{
public static void DoWork()
{
for(int i = 0; i<3;i++)
{
Console.WriteLine("Working thread...");
Thread.Sleep(100);
}
}
}
class ThreadTest
{
public static void Main()
{
ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
for(int i = 0; i<3; i++)
{
Console.WriteLine("In main.");
Thread.Sleep(100);
}
}
}
using namespace System;
using namespace System::Threading;
public ref class ThreadWork
{
public:
static void DoWork()
{
for ( int i = 0; i < 3; i++ )
{
Console::WriteLine( "Working thread..." );
Thread::Sleep( 100 );
}
}
};
int main()
{
ThreadStart^ myThreadDelegate = gcnew ThreadStart( &ThreadWork::DoWork );
Thread^ myThread = gcnew Thread( myThreadDelegate );
myThread->Start();
for ( int i = 0; i < 3; i++ )
{
Console::WriteLine( "In main." );
Thread::Sleep( 100 );
}
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note