473,770 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Terminating Systray Application On Shutdown does not work (it does not exit the app)

I have written an application that lives in the systray but when I try
to close windows or logout it does not close my application and
therefore prevents windows from shutting down or logging me out. It is
essential that I solve this problem but I have run out of ideas can
anyone help (please!)

The application starts in Start.cs which kicks off the Systray form
using this call:
Application.Run (new Systray());

Systray is a mimized form that is not visible in the TaskBar but has a
NotifyIcon which sits in the systray. Associate with the icon is a
context menu with a Terminate command in it i.e. Application.Exi t();
and that works fine. Presumably windows must send some sort of
terminate message to all running applications and I need to capture
that? Can I use one of the standard events or do I need to use the
windows WndProc?

Any suggestions of where to look would be greatly appreciated.

Regards, Jon
Nov 15 '05 #1
3 5496
Max
The general idea is that your application's main window should handle
WM_QUERYSHUTDOW N and WM_SHUTDOWN correctly.

Correctly means when you receive WM_QUERYSHUTDOW N you should answer whether
your are ready for it or wish to cancel the shutdown because of some unsaved
work, etc.
When you receive WM_SHUTDOWN - you should cancel.

Your application answers "yes" on query shutdown, but does not exit.

I do not know exactly how event handling for those events is implemented in
Windows.Forms. If you will not find out - you will need to overload windows
procedure (WndProc function).

"Jon Bosker" <Go*******@Visu alBasic.net> wrote in message
news:b1******** *************** ***@posting.goo gle.com...
I have written an application that lives in the systray but when I try
to close windows or logout it does not close my application and
therefore prevents windows from shutting down or logging me out. It is
essential that I solve this problem but I have run out of ideas can
anyone help (please!)

The application starts in Start.cs which kicks off the Systray form
using this call:
Application.Run (new Systray());

Systray is a mimized form that is not visible in the TaskBar but has a
NotifyIcon which sits in the systray. Associate with the icon is a
context menu with a Terminate command in it i.e. Application.Exi t();
and that works fine. Presumably windows must send some sort of
terminate message to all running applications and I need to capture
that? Can I use one of the standard events or do I need to use the
windows WndProc?

Any suggestions of where to look would be greatly appreciated.

Regards, Jon

Nov 15 '05 #2
Thanks Max - you have certainly helped me on my way. With that info I
found some more discussion and here is what I have got:
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x11: // WM_QUERYENDSESS ION
TerminateApp(fa lse);
break;

case 0x12: // WM_QUIT
TerminateApp(fa lse);
break;

case 0x16: // WM_ENDSESSION
TerminateApp(fa lse);
break;
}
base.WndProc(re f m);
}

My class TerminateApp then either asks the user if they want to
terminate (if true is passed as a parameter) and if not closes up
without question. This works in as much as the application is now
terminated when the user tries to shut down Windows but Windows still
does not close. The user has to tell Windows to shutdown a 2nd time
and this time it works because my application is gone. So.... can
anybody tell me why.... somehow I think I have to return a different
value to Windows (I think I need to return a 1?) but I cannot see how
to do that.

Regards, Jon
Nov 15 '05 #3
Max
See
http://msdn.microsoft.com/library/de...endsession.asp

It says you should return TRUE if you agree to cancel.
To the best of my knowledge it means that you you should set m.Result=1;

You do not need to actually close the window or application on Query End
Session. You should just decide if you are ready to close or not and respond
accordingly.

You will recieve WM_ENDSESSION. WM_ENDSESSION is a proper place to close.

See also SystemEvents.Se ssionEnding Event topic in Framework SDK
documentation to learn about the ".NET way" to handle it.

"Jon Bosker" <Jo*******@Yaho o.com> wrote in message
news:2f******** *************** ***@posting.goo gle.com...
Thanks Max - you have certainly helped me on my way. With that info I
found some more discussion and here is what I have got:
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x11: // WM_QUERYENDSESS ION
TerminateApp(fa lse);
break;

case 0x12: // WM_QUIT
TerminateApp(fa lse);
break;

case 0x16: // WM_ENDSESSION
TerminateApp(fa lse);
break;
}
base.WndProc(re f m);
}

My class TerminateApp then either asks the user if they want to
terminate (if true is passed as a parameter) and if not closes up
without question. This works in as much as the application is now
terminated when the user tries to shut down Windows but Windows still
does not close. The user has to tell Windows to shutdown a 2nd time
and this time it works because my application is gone. So.... can
anybody tell me why.... somehow I think I have to return a different
value to Windows (I think I need to return a 1?) but I cannot see how
to do that.

Regards, Jon

Nov 15 '05 #4

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

Similar topics

3
1888
by: Maxwell Hammer | last post by:
An application I am developing executes many threads and then has a "monitor" part that waits for certain events. One of these events causes the application to have to shutdown. On shutdown the monitor part notifies the threads of a shutdown, and the threads must cleanup and exit. When all threads have exited the monitor itself exits. The traceback below occured on a shutdown. At the time there was only one thread running, however the...
5
2566
by: Pint | last post by:
Is there a way to prevent my web application from shuting down if I don't have access to machine.config? Thanks, Pint
3
2112
by: Erik Greene | last post by:
I have written an application that contains a notifyicon that will not dispose or end when Windows shutsdown. I have seen other posts where people are experiencing the same issue (see post in the csharp group), so I know that this is an issues for others as well. Does anyone know how to capture the Windows Exit/Shutdown event?
1
1199
by: Dino Buljubasic | last post by:
I have application A and B Application A runs from its main() checks if B exists and if it does, runs application B (which also strarts from its main()). in task manager I can see A.exe and B.exe processes running I would like to closse A either while B is running or when B closes but when I close application B, application A still stays running in Task Manager.
2
1218
by: shachar | last post by:
hi all. i have a small application that i want it to appear in the systray when it's minimized. any simple example for me?
4
6809
by: Andrew | last post by:
I have ASP.NET 2.0 application. I'm running some initialization code in Application_Start() in Global.asax. If this code fails I would like to shutdown the application completely. Meaning no page, or an error page is returned to the user. I've tried HostingEnvironment.InitiateShutdown() but it's async and still returns a page to the user. According to msdn this method is equivalent to ApplicationManager.ShutdownApplication()...
6
2044
by: Mad Scientist Jr | last post by:
My asp.net pages sessions are timing out after 20 minutes, and when I asked my Web host about it they said due to the nature of a shared hosting environment they cannot allow for sessions to keep application pools and worker processes hosed for too long as these fearures are consuming CPU resources while they are active. Therefore the pool application shutdown and re-start settings are at 20 minutes. Is there a workaround for this? Do I...
3
3283
by: Bill Davidson | last post by:
All: I have a problem in which a worker thread in my (.dll) assembly isn't allowing the main (.exe) assembly from terminating. Here's the scenario: 1) App.Exe is launched. 2) App.Exe calls into my .dll (Sub.Dll)
0
9432
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,...
0
10059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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
5313
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
3578
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.