Form.Close() hangs when invoked from thread
Hi,
I have a windows form that starts another thread. When the thread's work is done, I want the thread to go ahead and close the form. To make it thread safe, what I did was the following:
//This is a delegate
privatedelegatevoidCloseFormSafely();
...
//This is in the thread that's defind in the form
this.CloseSafely();
}
...
//also in the form
privatevoid CloseSafely()
{
if (this.InvokeRequired)
{
CloseFormSafely d =newCloseFormSafely(CloseSafely);
this.Invoke(d);
}
else
{
this.Close();
}
}
While this works all fine in VS.Net 2003, it for some reason doesn't work in VS.Net 2005 when I run in debug mode. The execution stops and freaz at "this.Close();". I have to stop debugging to get out. Am I missing something here?
Please help!
Thanks!
Feng

