I have following code
private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
} // btnClose_Click
After running the close winforms function the application freezes. Any idea why it can happen?
I use .net 2.0 and i run under Windows 7 vs2005
EDIT:
After I pressed pause in the debugger I came to
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// GUI
if (FScannerThread_Running)
{
FScannerThread_Running = false;
FScannerThread.Join();
}
}
And it stacked in FScannerThread.Join(); any idea how i can kill it ?
Use the bool Thread.Join(int milliseconds) overload, and if the result is false, Abort() your thread.
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// GUI
if (FScannerThread_Running)
{
FScannerThread_Running = false;
if (!FScannerThread.Join(1000)) // Give the thread 1 sec to stop
{
FScanner.Abort();
}
}
}
Note that you should catch ThreadAbortException in your thread in order to end it gracefully (if you have something to release for instance).
When it is freezed, call pause (Break all) in the debug menu - you'll see where diferent threads of your app could hang up. The platform here does not matter. Sometimes that can happen if you have multithreaded app and in some thread the state was corrupted or something like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With