C# program for sleep(), abort() and join() methods
Program.cs
Thread t1 = new Thread(new ThreadStart(KWThread.thread));
Thread t2 = new Thread(new ThreadStart(KWThread.thread));
t1.Start();
t2.Start();
t1.Join();
Console.WriteLine("Thread Interrupted");
t1.Interrupt();
t2.Interrupt();

public class KWThread
{
    public static void thread()
    {
        for (int i = 0; i < 5; i++)
        {
            Console.Write(i + " ");
            Thread.Sleep(200);
        }
    }
}
Output
kodingwindow@kw:~/csharp$ dotnet run
0 0 1 1 2 2 3 3 4 4 Thread Interrupted
kodingwindow@kw:~/csharp$ 
Advertisement