Skip to main content
.NET Framework Class Library
Thread..::.Start Method

Causes the operating system to change the state of the current instance to ThreadState..::.Running.

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Syntax
<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 
Exceptions
ExceptionCondition
ThreadStateException

The thread has already been started.

OutOfMemoryException

There is not enough memory available to start this thread.

Remarks

Once a thread is in the ThreadState..::.Running state, the operating system can schedule it for execution. The thread begins executing at the first line of the method represented by the ThreadStart or ParameterizedThreadStart delegate supplied to the thread constructor.

NoteNote

If this overload is used with a thread created using a ParameterizedThreadStart delegate, nullNothingnullptra null reference (Nothing in Visual Basic) is passed to the method executed by the thread.

Once the thread terminates, it cannot be restarted with another call to Start.

NoteNote

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.

Examples

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 );

   }
}


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library
Platforms

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.