Join, Sleep and Abort methods in C# Threading

ProgrammingServer Side ProgrammingCsharp


Blocks the calling thread until a thread terminates, while continuing to perform standard COM and SendMessage pumping. This method has different overloaded forms.


Makes the thread pause for a period of time.


The Abort method is used to destroy threads.

Let us see an example of Join() in threading −


using System;
using System.Diagnostics;
using System.Threading;
namespace Sample {
   class Demo {
      static void Run() {
         for (int i = 0; i < 2; i++)
         Console.Write("Sample text!");
      static void Main(string[] args) {
         Thread t = new Thread(Run);
         Console.WriteLine("Thread terminated!");

Let us see an example of abort() and sleep() in Threading.


using System;
using System.Threading;
namespace Demo {
   class ThreadCreationProgram {
      public static void CallToChildThread() {
         try {
            Console.WriteLine("Child thread starts");
            // do some work, like counting to 10
            for (int counter = 0; counter <= 10; counter++) {
            Console.WriteLine("Child Thread Completed");
         } catch (ThreadAbortException e) {
            Console.WriteLine("Thread Abort Exception");
         } finally {
            Console.WriteLine("Couldn't catch the Thread Exception");
      static void Main(string[] args) {
         ThreadStart childref = new ThreadStart(CallToChildThread);
         Console.WriteLine("In Main: Creating the Child thread");
         Thread childThread = new Thread(childref);
         //stop the main thread for some time
         //now abort the child
         Console.WriteLine("In Main: Aborting the Child thread");
Published on 11-Sep-2018 09:32:18