473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Aug 22 '06 #1
5 5680
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
Ole wrote:
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
Aug 22 '06 #2
Ole wrote:
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/lib...orm.close.aspx

http://blogs.msdn.com/tom_krueger/ar...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
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 22 '06 #3
Ole
Thanks!

"Andreas Mueller" <me@privacy.netwrote in message
news:4l************@individual.net...
Ole wrote:
>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/lib...orm.close.aspx
http://blogs.msdn.com/tom_krueger/ar...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
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm

Aug 22 '06 #4
Ole
Thanks a lot! Btw - do you have an idea of how to close a similar
windowsless apllication from code?

Best regards,
Ole

"Andreas Mueller" <me@privacy.netwrote in message
news:4l************@individual.net...
Ole wrote:
>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/lib...orm.close.aspx
http://blogs.msdn.com/tom_krueger/ar...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
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm

Aug 22 '06 #5
Ole wrote:
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

--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Galey | last post by:
VB.NET 2002 on Windows 2000 SP 3 When I start my program, the NotifyIcon appears in the tray, as it should. However, when I close the program, the NotifyIcon remains until I hover over it with...
9
by: Tommy Lu | last post by:
Hi, wondering if there is a way to interact the shell command with the C# program? For example, if I type c:\>ver it then suppose to return the version of the OS I am currently using... or ...
1
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). ...
1
by: Alex Bink | last post by:
Hi, Anyone knows how to prevent the validating event of a control to be fired when the user clicks the close button? The OnClosing event of the form seems to be to late and setting the form's...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
10
by: Ricky W. Hunt | last post by:
I have written a close routine to handle an "Exit" button to close the application properly. How do I make sure this gets executed if the user closes it another way (by pressing the "X" in the...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
1
by: Phill W. | last post by:
Has any come across a situation where, in a Form-derived .. er .. Form, the Event Arguments passed to OnClosing /already/ have their Cancel argument set to True? Protected Overrides Sub...
7
by: Jay | last post by:
In my C# code, I'm attempting to display a message box then quit the win form application I'm writing if a certain type of error occurs when the application starts up. In the main form's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.