Hi I have following test code:
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(Work);
t.Start();
Thread.Sleep(1000);
t.Abort();
Thread.Sleep(1000);
t.Abort();
Thread.Sleep(1000);
t.Abort();
t.Join();
Console.WriteLine("End");
}
static void Work()
{
int i = 0;
while (i<10)
{
try
{
while(true);
}
catch(ThreadAbortException)
{
Thread.ResetAbort();
}
Console.WriteLine("I will come back!");
i++;
}
}
}
Everytime, when there is an abort, Thread.ResetAbort() will be executed. I wonder what this ResetAbort does. Because when I run it, I saw the following output: I will come back! I will come back! I will come back! And I didn't see the output "End" - it seems this program didn't end at all. Do you know why? Thanks!
It cancels the request to abort the thread. As indicated here. So in this case the loop will continue and the thread should still be alive.