System.Threading.Thread.Start Method

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

Syntax

public void Start ()

Exceptions

TypeReason
OutOfMemoryExceptionThere is not enough memory available to start the thread.
NullReferenceExceptionThis method was invoked on a null thread reference.
System.Threading.ThreadStateExceptionThe thread has already been started.

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 System.Threading.ThreadStart or System.Threading.ParameterizedThreadStart delegate supplied to the thread constructor.

Note:

If this overload is used with a thread created using a System.Threading.ParameterizedThreadStart delegate, null is passed to the method executed by the thread.

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

Example

The following example demonstrates creating a thread and starting it.

C# Example

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

One possible set of output is

In main.
Working thread ...
In main.
Working thread ...
In main.
Working thread ...

Note that the sequence of the output statements is not guaranteed to be identical across systems.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0