using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace AbortExceptionSample
{
class Abort_Exception
{
public static void ChildThreadcall()
{
try
{
Console.WriteLine("Child Thread Started");
Console.WriteLine("Child thread - counting to 10");
for (int i = 0; i <= 10; i++)
{
Thread.Sleep(2000);
Console.WriteLine("{0}...", i);
}
Console.WriteLine("Child Thread Finished");
}
catch (ThreadAbortException e)
{
Console.WriteLine(e.Message);
}
}
public static void Main(string[] args)
{
ThreadStart childRef = new ThreadStart(ChildThreadcall);
Thread ChildThread = new Thread(childRef);
ChildThread.Start();
Console.WriteLine("Main - Sleping for 2secs");
Thread.Sleep(5000);
Console.WriteLine("\nMain - Aborting Child Thread");
ChildThread.Abort();
}
}
}
Download Thread Source Code
No comments:
Post a Comment