You did not provide a complete code sample so it's hard to tell what's
really going on.
I'd be surprised if the thread that the function ShowProgressBar executes on
behaves as you think it does. Just because you catch a ThreadAbortException
does not mean that you've handled it completely. After the catch block
completes the runtime will rethrow the exception again unless you call
ResetAbort. If you do not call ResetAbort then eventually that entire thread
of execution will terminate and you will see an unhandled exception - if
this was the main thread of execution then your app crashes.
Another potential problem is that you may be updating controls on threads
other then the thread on which the control was created.
In general, don't abort a thread unless you know what all the side effects
are. There are other and better ways to cause a thread to terminate in a
graceful manner. Also, controls should usually be updated on the same thread
that created them. You can use the Control.InvokeRequired field to test for
this.
"mphanke" <mp*****@nospam.nospam> wrote in message
news:e3*************@TK2MSFTNGP12.phx.gbl...
Hi,
Thanks for the hint, but didn't help!
So my Main() looks like :
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}
The func which starts the thread and displays the progress bar looks like:
Thread g_Thread;
private void ShowProgressBar()
{
DataProgress dp = new DataProgress(true); // true->start the timer
immediately
try
{
dp.ShowDialog();
dp.Activate();
}
catch(ThreadAbortException abortException)
{
dp.StopTimer(); // stop the timer
dp.SetTitle((string)abortException.ExceptionState) ; // set this to be
the final message
dp.Close(); // close -> and crash if visualstyles enabled ->
WindowsFormsParkingWindow
}
}
private void StartStopThread(bool b, string str)
{
if(b)
{
g_Thread = new Thread(new ThreadStart(ShowProgressBar));
g_Thread.Start();
Thread.Sleep(250);
}
else
{
if(g_Thread.IsAlive)
{
g_Thread.Abort(str);
Thread.Sleep(250);
}
}
}
Hope this makes things clearer now.
Martin
Frans Bouma [C# MVP] wrote: mphanke wrote:
Hi,
everytime I enable the Visualstyles on in my app it keeps crashing at a
point, where I close my progress window with progressdialog.close(). It
runs in a seperate thread and contains a timer and a progressbar- if
thisis of interest.
After you enable it do: Application.DoEvents();
FB