Threading Concepts

Threading enables C# program to perform 
concurrent processing so that you can do more than one operation at a time.

The System.Threading namespace provides classes and interfaces that support multithreaded
programming and enable you to easily perform tasks such as creating and
starting new threads, synchronizing multiple threads, suspending
threads, and aborting threads.

System.Threading.Thread newThread;
newThread = new System.Threading.Thread(anObject.AMethod);
newThread.Start();


Creating a new Thread object creates a new managed thread. The Thread  class has constructors that take a ThreadStart  delegate or a ParameterizedThreadStart  delegate; 

ThreadStart Delegate

Represents the method that executes on a Thread  

ParameterizedThreadStart Delegate

Represents the method that executes on a Thread 
using System;
using System.Threading;

class Test
{
static void Main()
{


ThreadStart threadDelegate = new ThreadStart(Work.DoWork);
Thread newThread = new Thread(threadDelegate);
newThread.Start();

Sandeep w = new Sandeep();
w.Data = 42;
threadDelegate = new ThreadStart(w.DoMoreWork);
newThread = new Thread(threadDelegate);
newThread.Start();
}
}

class Sandeep
{
public static void DoWork()
{
Console.WriteLine("Static thread procedure.");
}
public int Data;
public void DoMoreWork()
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}
}

/* This code example produces the following output (the order
of the lines might vary):
Static thread procedure.
Instance thread procedure. Data=42
*/