Tuesday, June 9, 2009

Multithreading

Threading allows a program to execute two or more execution paths in parallel. Threading does not require a multi-processor multi-core processor to run.

Hear the simple program do's that

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MultiThreading
{
class Program
{
static void Main(string[] args)
{
ThreadStart thread = new ThreadStart(NestedThread);
Thread th = new Thread(thread);
th.Start();
for (int i = 0; i <= 100; i++)
{
Console.WriteLine("Main Thread : " + i.ToString());
Thread.Sleep(300);
}
}
protected static void NestedThread()
{
for(int i =0;i<=200;i++)
{
Console.WriteLine("Parallel Thread : " + i.ToString());
Thread.Sleep(200);
}
}
}
}