Search This Blog

Monday, August 9, 2010

Implementing threads in c#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace threads
{
class Program
{
public static void pendrive()
{
for (int i = 0; i <= 5; i++)
{
Console.WriteLine("Port is assigned to pendrive.");
Thread.Sleep(4000);
}
}
public static void printer()
{
for (int i = 0; i <= 4; i++)
{
Console.WriteLine("Port is assigned to printer.");
Thread.Sleep(2000);
}
}
public static void harddisk()
{
for (int i = 0; i <= 3; i++)
{
Console.WriteLine("Port is assigned to harddisk.");
Thread.Sleep(3000);
}
}
static void Main(string[] args)
{
ThreadStart ts1 = new ThreadStart(pendrive);
Thread t1 = new Thread(ts1);
ThreadStart ts2 = new ThreadStart(printer);
Thread t2 = new Thread(ts2);
ThreadStart ts3 = new ThreadStart(harddisk);
Thread t3 = new Thread(ts3);
t1.Start();
t2.Start();
t3.Start();
Console.WriteLine("main ended.");
}
}
}

No comments:

Post a Comment