In my app I've got a thread which displays for some time "please wait" dialog window, sometimes it is a very tiny amout of time and there is some glitch while drawing UI (I guess).
I get the exception "Thread was being aborted" and completly have no idea how get rid of it. I mean Catch that exception in some way, or in some other way hide it from user. This exception has got nothing to do with rest of my app and that error in any way doesn't affect it. Appears randomly and it is hard to recreate on a call.
I tried in various ways to catch that exception by side of code which starts and stops thread with dialog window but it seems that error apparently is by side some other thread which dispalys window in my newly created thread.
Here is a code sample, part of static class with useful stuff, of course I don't say that is good way to solve this kind of "busy" situation but I want to solve this problem. Thread.Sleep(500); or other try/catch improvments doesn't help me to avoid that thread exception.
public static bool alreadyBusy = false;
public static BusyIndicator bi = new BusyIndicator("");
public static Thread backgroundOpertionThread;
public static void showBusy(bool isBusy, System.Windows.Forms.Form hostform, string message)
{
Common.busyMessage = message;
if (isBusy)
{
Common.alreadyBusy = true;
backgroundOpertionThread = new Thread(new ThreadStart(showBusy));
Thread.Sleep(500);
if (hostform != null)
{
hostform.Enabled = false;
hostform.SuspendLayout();
}
backgroundOpertionThread.Start();
}
else
{
backgroundOpertionThread.Abort();
Thread.Sleep(500);
Common.alreadyBusy = false;
if (hostform != null)
{
hostform.Enabled = true;
hostform.ResumeLayout();
}
}
}
public static void showBusy()
{
BusyIndicator bir = new BusyIndicator(Common.busyMessage);
bir.ShowDialog();
}
Any ideas?