473,775 Members | 2,340 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 5717
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
5043
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
17710
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
2720
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
4314
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
9621
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
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10046
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,...
1
7463
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
6717
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
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4014
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
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.