Application.Exit doesn't raise the OnClosing event???

O

Ole

The Application.Exit (called from a worker thread) method doesn't cause the
OnClosing event handler to be run - is that a default behaviour??? If so -
what should I do to properly close all threads etc.

Thanks
Ole
 
J

Johnny Thawte

As a general rule, wouldn't it be better to have the worker thread
alert the parent process that a close application has been requested?

The parent process could take care of cleaning up after all the
threads, as it's the only process that would properly know about all
the worker threads.

Just a thought...

Johnny Thawte
http://www.johnnysthoughts.com
 
A

Andreas Mueller

Ole said:
The Application.Exit (called from a worker thread) method doesn't cause the
OnClosing event handler to be run - is that a default behaviour??? If so -
what should I do to properly close all threads etc.

Thanks
Ole

This is the default behavior:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.close.aspx

http://blogs.msdn.com/tom_krueger/archive/2005/02/24/379678.aspx


You can hook the Application.ApplicationExit event or call the Close()
method of your main form. This has the advantage that all expected
events are raised

If you decide to call the close method, remember to invoke the call when
you are not in the Gui Thread:

private delegate void NullaryFunction();
private void CloseForm()
{
Debug.Assert(mainForm != null && mainForm.IsHandleCreated);
if (mainForm.InvokeRequired)
mainForm.BeginInvoke(new NullaryFunction(mainForm.Close));
else
mainForm.Close();
}


HTH,
Andy
 
O

Ole

Thanks!

Andreas Mueller said:
This is the default behavior:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.close.aspx
http://blogs.msdn.com/tom_krueger/archive/2005/02/24/379678.aspx


You can hook the Application.ApplicationExit event or call the Close()
method of your main form. This has the advantage that all expected events
are raised

If you decide to call the close method, remember to invoke the call when
you are not in the Gui Thread:

private delegate void NullaryFunction();
private void CloseForm()
{
Debug.Assert(mainForm != null && mainForm.IsHandleCreated);
if (mainForm.InvokeRequired)
mainForm.BeginInvoke(new NullaryFunction(mainForm.Close));
else
mainForm.Close();
}


HTH,
Andy
 
O

Ole

Thanks a lot! Btw - do you have an idea of how to close a similar
windowsless apllication from code?

Best regards,
Ole
 
A

Andreas Mueller

Ole said:
Thanks a lot! Btw - do you have an idea of how to close a similar
windowsless apllication from code?

Best regards,
Ole

Not a general one, because that really depends on the application type.

Cheers,
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top