473,788 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Ole
The Application.Exi t (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 5718
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.Exi t (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.Exi t (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.App licationExit 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(ma inForm != null && mainForm.IsHand leCreated);
if (mainForm.Invok eRequired)
mainForm.BeginI nvoke(new NullaryFunction (mainForm.Close ));
else
mainForm.Close( );
}
HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.netNOSPAm
Aug 22 '06 #3
Ole
Thanks!

"Andreas Mueller" <me@privacy.net wrote in message
news:4l******** ****@individual .net...
Ole wrote:
>The Application.Exi t (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.App licationExit 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(ma inForm != null && mainForm.IsHand leCreated);
if (mainForm.Invok eRequired)
mainForm.BeginI nvoke(new NullaryFunction (mainForm.Close ));
else
mainForm.Close( );
}
HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.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.net wrote in message
news:4l******** ****@individual .net...
Ole wrote:
>The Application.Exi t (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.App licationExit 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(ma inForm != null && mainForm.IsHand leCreated);
if (mainForm.Invok eRequired)
mainForm.BeginI nvoke(new NullaryFunction (mainForm.Close ));
else
mainForm.Close( );
}
HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.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**********@gm xNOSPAm.netNOSPAm
Aug 22 '06 #6

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

Similar topics

5
7365
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 my mouse. If I don't hover over it to make it disappear and then open the program again, another one is added, resulting in a multiplicity of the icon in the tray. I've even tried setting its Visible property to false, followed by a call to the...
9
5044
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 c:\>systeminfo
1
17714
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). The form has a really long loop which generates approx. 700 .csv files. I do not create any threads myself (Application.exitthread() doesn't work either). To counteract this I have decided to use the Environment.exit(-1) method instead. What...
1
1714
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 CausesValidation property to false doesn't seem to help either... Thanks...
6
20087
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 quite a few words in this post but the questions are actually quite similar and should be fairly quick to answer ... (1) What is Happening with the Threads
10
1835
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 upper right hand for instance, or Alt+4, etc.) Or is this even necessary? -- Thanks, Ricky W. Hunt freendeed
20
2723
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 contrast to one of them always being 'modal' (e.g., if you are moving over a picture the 'Info' form will update the (x,y) screen location in realtime even if not the selected form. Also note that this example implies the various forms can communicate...
1
4091
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 OnClosing( _ ByVal e As System.ComponentModel.CancelEventArgs _ ) Debug.WriteLine("e.Cancel=(" & e.Cancel.ToString() & ")") ' It's True already !!
7
4315
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 constructor - FormMain() - if this error occurs, I display a message box then call Application.Exit(). The problem is that I also need to have some code in my FormMain_FormClosing event handler, but this prevents Application.Exit() from quitting the...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10370
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.