Threading is a concept of C# wherein, you can do more than one operation at a time by allowing your program to do processing concurrently.
Code:
using System;
using System.Threading;
public class emp
{
public void AssgnWrk()
{
while (!endit)
{
Console.WriteLine("Employee Thread: working...");
}
Console.WriteLine("Employee thread: Terminating");
}
public void Halt()
{
endit = true;
}
private volatile bool endit;
}
public class EmpThread
{
static void Main()
{
emp e = new emp();
Thread EmpThread = new Thread(e.AssgnWrk);
EmpThread.Start();
Console.WriteLine("The Main Thread: Beginning Employee Thread");
while (!EmpThread.IsAlive);
Thread.Sleep(1);
e.Halt();
EmpThread.Join();
Console.WriteLine("The Main Thread: Employee Thread Destroyed.");
}
}
Bookmarks