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)

public void Start ()
public void Start ()
public function Start ()
Not applicable.

Exception typeCondition

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.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, a 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.

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.

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

import System.*;
import System.Threading.*;
public class ThreadWork
{
    public static void DoWork()
    {
        for (int i = 0; i < 3; i++) {
            Console.WriteLine("Working thread...");
            System.Threading.Thread.Sleep(100);
        }
    } //DoWork
} //ThreadWork

class ThreadTest
{
    public static void main(String[] args)
    {
        ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
        System.Threading.Thread myThread =
            new System.Threading.Thread(myThreadDelegate);
        myThread.Start();
        for (int i = 0; i < 3; i++) {
            Console.WriteLine("In main.");
            System.Threading.Thread.Sleep(100);
        }
    } //main
} //ThreadTest

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show: