I've inherited some code from a previous developer and the app occasionally gives a thread abort exception when performing a certain task.
private void popup()
{
Thread th = new Thread(() =>
{
try
{
OpenForm();
}
catch (ThreadAbortException ex)
{
Console.WriteLine("Thread was forcibly aborted");
}
});
th.Start();
while (fromflag)
{
}
th.Abort();
}
The thread opens a popup with an animated loading gif, downloads files from a server and then completes. I set fromflag to false when done. I can't set a timer as it can take any time to download the files.
How can I write this differently so then I don't have to use th.Abort and the thread closes itself when complete?