One of my applications prevents windows from closing if it is running.
The only place I suspect the reason could be the FormClosing event handler, which, however, is pretty standard:
EDIT: Removing this handler does not make a difference at all, so the reason is somewhere else.
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.UserClosing)
{
StopAllThreads();
return;
}
}
I could not reproduce this with the simplest possible application containing only this FormClosing handler - a simple application closes correctly when windows start to close.
What else can prevent windows from closing? Where should I look for code to debug this problem?
I do not have a special implementation of WndProc in my main form. This is a .NET 2.0 application.
, " Windows " (Windows 7) . Windows Visual Studio, , .
EDIT: StopAllThreads
public static void StopAllThreads()
{
lock (syncLock)
{
foreach (IStop stoppable in stoppables)
{
try
{
stoppable.Stop();
}
catch (Exception ex)
{
Debug.Fail("Error stopping a stoppable instance: " + ex.ToString());
}
}
stoppables.Clear();
disposed = true;
}
}
: , .