C# Program to Destroy the Thread

Destroying the thread:-
 

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

namespace ConsoleApplication2
{
    class mainthread
    {
        public static void ChildCall()
        {
            try
            {
                Console.WriteLine(“Child thread is starting”);
                Console.WriteLine(“Counting from 1 to 10”);
                for (int i = 0; i <= 9; i++)
                {
                    Thread.Sleep(600);
                    Console.Write(“{0}…..”, i);
                }
                Console.WriteLine(“Child sleeping”);
            }
            catch (ThreadAbortException e)
            {
                Console.WriteLine(“Exception”);
            }
            finally
            {
                Console.WriteLine(“Unable to catch exception”);
            }
        }
           public static void Main(string[] args)
        {
            ThreadStart th = new ThreadStart(ChildCall);
            Console.WriteLine(“Requesting to Start”);
            Thread create = new Thread(th);
            Console.WriteLine(“Starting the Thread”);
            create.Start();
               Console.WriteLine(“slepping for second”);
               Thread.Sleep(4000);
               Console.WriteLine(“Aborting the Process”);
               create.Abort();
            Console.ReadLine();
        }
    }
}
 

Add Comment