473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can you detect application close event with no form?

I have an vb.net application that is a module that uses a "application.run"
in the sub main to start. There is no form involved (just a system tray
icon)
How can you detect when the application is being closed? It is easy enough
if the user selects "exit" from this tray icon but how can you detect if
Windows is closing the program down? Normally I would simply do something in
the Form.Closing event but without a form how can you determine that the
application is being closed by Windows?
Nov 21 '05 #1
12 17017
Just call Application.Exit

"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in message
news:et****************@TK2MSFTNGP09.phx.gbl...
I have an vb.net application that is a module that uses a "application.run"
in the sub main to start. There is no form involved (just a system tray
icon)
How can you detect when the application is being closed? It is easy
enough if the user selects "exit" from this tray icon but how can you
detect if Windows is closing the program down? Normally I would simply do
something in the Form.Closing event but without a form how can you
determine that the application is being closed by Windows?

Nov 21 '05 #2
Application.Exit simply exits the program. I want to know how to detect
that Windows is telling my application to shut down. For example when
Windows is shutting down or restarting it will close all running
applications. I want to know how to detect that event when there is no form
in the application.
"Marina" <so*****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Just call Application.Exit

"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in
message news:et****************@TK2MSFTNGP09.phx.gbl...
I have an vb.net application that is a module that uses a
"application.run" in the sub main to start. There is no form involved
(just a system tray icon)
How can you detect when the application is being closed? It is easy
enough if the user selects "exit" from this tray icon but how can you
detect if Windows is closing the program down? Normally I would simply do
something in the Form.Closing event but without a form how can you
determine that the application is being closed by Windows?


Nov 21 '05 #3

a long time ago, fergus suggested this to me...and it works just fine...

somewhere in your initialisation code:

either event will work just fine, but read the differences so you know which
is most appropriate for what you want to accomplish.

AddHandler ( _
SystemEvents.SessionEnding, _
AddressOf ShutDown.OnShuttingDown _
)
AddHandler ( _
SystemEvents.SessionEnded, _
AddressOf ShutDown.OnShutDown _
)

put the following class somewhere

Public Class ShutDown
Public Shared Sub OnShuttingdown( _
sender As Object, _
e As SessionEndingEventArgs _
)
e.Cancel = True 'only set if you turn down the shutdown request
Console.WriteLine ("Shutting down - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub

Public Shared Sub OnShutdown ( _
sender As Object, _
e As SessionEndedEventArgs _
)
Console.WriteLine ("Shutdown - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub
End Class

i'll be happy to help you if you can't figure out how to incorporate this
snippet into your application.

hth,

me

Nov 21 '05 #4

That looks good but the "AddHandler" lines simply say "syntax error" in
vb.net. I've added them to the top under the variable declarations and
within the sub main but they always show syntax error.
"" <a@b.com> wrote in message news:lm******************@fe05.lga...
a long time ago, fergus suggested this to me...and it works just fine...

somewhere in your initialisation code:

either event will work just fine, but read the differences so you know
which
is most appropriate for what you want to accomplish.

AddHandler ( _
SystemEvents.SessionEnding, _
AddressOf ShutDown.OnShuttingDown _
)
AddHandler ( _
SystemEvents.SessionEnded, _
AddressOf ShutDown.OnShutDown _
)

put the following class somewhere

Public Class ShutDown
Public Shared Sub OnShuttingdown( _
sender As Object, _
e As SessionEndingEventArgs _
)
e.Cancel = True 'only set if you turn down the shutdown request
Console.WriteLine ("Shutting down - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub

Public Shared Sub OnShutdown ( _
sender As Object, _
e As SessionEndedEventArgs _
)
Console.WriteLine ("Shutdown - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub
End Class

i'll be happy to help you if you can't figure out how to incorporate this
snippet into your application.

hth,

me

Nov 21 '05 #5
Ignore my previous post. I figured out where to place them. Thanks!

"" <a@b.com> wrote in message news:lm******************@fe05.lga...
a long time ago, fergus suggested this to me...and it works just fine...

somewhere in your initialisation code:

either event will work just fine, but read the differences so you know
which
is most appropriate for what you want to accomplish.

AddHandler ( _
SystemEvents.SessionEnding, _
AddressOf ShutDown.OnShuttingDown _
)
AddHandler ( _
SystemEvents.SessionEnded, _
AddressOf ShutDown.OnShutDown _
)

put the following class somewhere

Public Class ShutDown
Public Shared Sub OnShuttingdown( _
sender As Object, _
e As SessionEndingEventArgs _
)
e.Cancel = True 'only set if you turn down the shutdown request
Console.WriteLine ("Shutting down - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub

Public Shared Sub OnShutdown ( _
sender As Object, _
e As SessionEndedEventArgs _
)
Console.WriteLine ("Shutdown - Reason is " & e.Reason)
' your code here to clean up before exiting
End Sub
End Class

i'll be happy to help you if you can't figure out how to incorporate this
snippet into your application.

hth,

me

Nov 21 '05 #6

np...let me know how it works.
"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in message
news:Ot**************@TK2MSFTNGP09.phx.gbl...
| Ignore my previous post. I figured out where to place them. Thanks!
|
| "" <a@b.com> wrote in message news:lm******************@fe05.lga...
| >a long time ago, fergus suggested this to me...and it works just fine...
| >
| > somewhere in your initialisation code:
| >
| > either event will work just fine, but read the differences so you know
| > which
| > is most appropriate for what you want to accomplish.
| >
| > AddHandler ( _
| > SystemEvents.SessionEnding, _
| > AddressOf ShutDown.OnShuttingDown _
| > )
| > AddHandler ( _
| > SystemEvents.SessionEnded, _
| > AddressOf ShutDown.OnShutDown _
| > )
| >
| > put the following class somewhere
| >
| > Public Class ShutDown
| > Public Shared Sub OnShuttingdown( _
| > sender As Object, _
| > e As SessionEndingEventArgs _
| > )
| > e.Cancel = True 'only set if you turn down the shutdown request
| > Console.WriteLine ("Shutting down - Reason is " & e.Reason)
| > ' your code here to clean up before exiting
| > End Sub
| >
| > Public Shared Sub OnShutdown ( _
| > sender As Object, _
| > e As SessionEndedEventArgs _
| > )
| > Console.WriteLine ("Shutdown - Reason is " & e.Reason)
| > ' your code here to clean up before exiting
| > End Sub
| > End Class
| >
| > i'll be happy to help you if you can't figure out how to incorporate
this
| > snippet into your application.
| >
| > hth,
| >
| > me
| >
| >
| >
|
|
Nov 21 '05 #7
I rebooted my computer to test it but it works great! That was exactly what
I needed!
Thanks!
"" <a@b.com> wrote in message news:2I******************@fe05.lga...
np...let me know how it works.
"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in
message
news:Ot**************@TK2MSFTNGP09.phx.gbl...
| Ignore my previous post. I figured out where to place them. Thanks!
|
| "" <a@b.com> wrote in message news:lm******************@fe05.lga...
| >a long time ago, fergus suggested this to me...and it works just
fine...
| >
| > somewhere in your initialisation code:
| >
| > either event will work just fine, but read the differences so you know
| > which
| > is most appropriate for what you want to accomplish.
| >
| > AddHandler ( _
| > SystemEvents.SessionEnding, _
| > AddressOf ShutDown.OnShuttingDown _
| > )
| > AddHandler ( _
| > SystemEvents.SessionEnded, _
| > AddressOf ShutDown.OnShutDown _
| > )
| >
| > put the following class somewhere
| >
| > Public Class ShutDown
| > Public Shared Sub OnShuttingdown( _
| > sender As Object, _
| > e As SessionEndingEventArgs _
| > )
| > e.Cancel = True 'only set if you turn down the shutdown request
| > Console.WriteLine ("Shutting down - Reason is " & e.Reason)
| > ' your code here to clean up before exiting
| > End Sub
| >
| > Public Shared Sub OnShutdown ( _
| > sender As Object, _
| > e As SessionEndedEventArgs _
| > )
| > Console.WriteLine ("Shutdown - Reason is " & e.Reason)
| > ' your code here to clean up before exiting
| > End Sub
| > End Class
| >
| > i'll be happy to help you if you can't figure out how to incorporate
this
| > snippet into your application.
| >
| > hth,
| >
| > me
| >
| >
| >
|
|

Nov 21 '05 #8

great...always glad to pass along a good tip...thanks to fergus for pointing
out the systemevents class and the associated snippet.
"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
|I rebooted my computer to test it but it works great! That was exactly
what
| I needed!
| Thanks!
|
|
| "" <a@b.com> wrote in message news:2I******************@fe05.lga...
| > np...let me know how it works.
| >
| >
| > "Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> wrote in
| > message
| > news:Ot**************@TK2MSFTNGP09.phx.gbl...
| > | Ignore my previous post. I figured out where to place them. Thanks!
| > |
| > | "" <a@b.com> wrote in message news:lm******************@fe05.lga...
| > | >a long time ago, fergus suggested this to me...and it works just
| > fine...
| > | >
| > | > somewhere in your initialisation code:
| > | >
| > | > either event will work just fine, but read the differences so you
know
| > | > which
| > | > is most appropriate for what you want to accomplish.
| > | >
| > | > AddHandler ( _
| > | > SystemEvents.SessionEnding, _
| > | > AddressOf ShutDown.OnShuttingDown _
| > | > )
| > | > AddHandler ( _
| > | > SystemEvents.SessionEnded, _
| > | > AddressOf ShutDown.OnShutDown _
| > | > )
| > | >
| > | > put the following class somewhere
| > | >
| > | > Public Class ShutDown
| > | > Public Shared Sub OnShuttingdown( _
| > | > sender As Object, _
| > | > e As SessionEndingEventArgs _
| > | > )
| > | > e.Cancel = True 'only set if you turn down the shutdown request
| > | > Console.WriteLine ("Shutting down - Reason is " & e.Reason)
| > | > ' your code here to clean up before exiting
| > | > End Sub
| > | >
| > | > Public Shared Sub OnShutdown ( _
| > | > sender As Object, _
| > | > e As SessionEndedEventArgs _
| > | > )
| > | > Console.WriteLine ("Shutdown - Reason is " & e.Reason)
| > | > ' your code here to clean up before exiting
| > | > End Sub
| > | > End Class
| > | >
| > | > i'll be happy to help you if you can't figure out how to incorporate
| > this
| > | > snippet into your application.
| > | >
| > | > hth,
| > | >
| > | > me
| > | >
| > | >
| > | >
| > |
| > |
| >
| >
|
|
Nov 21 '05 #9
"Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> schrieb:
That looks good but the "AddHandler" lines simply say "syntax error" in
vb.net. I've added them to the top under the variable declarations and
within the sub main but they always show syntax error.
[...]
AddHandler ( _
SystemEvents.SessionEnding, _
AddressOf ShutDown.OnShuttingDown _
)


Remove the braces ('(', ')').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #10


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
| "Patrick Dugan" <pa***********@usnetNOSMORESPAMcomcorp.com> schrieb:
| > That looks good but the "AddHandler" lines simply say "syntax error" in
| > vb.net. I've added them to the top under the variable declarations and
| > within the sub main but they always show syntax error.
| > [...]
| >> AddHandler ( _
| >> SystemEvents.SessionEnding, _
| >> AddressOf ShutDown.OnShuttingDown _
| >> )
|
| Remove the braces ('(', ')').

once again herf, it is you who needs to remove something...your head from
your ass. the syntax is NOT a problem. if you knew what the hell you were
talking about, you know the problem was *where* the op placed this code.

why are you an "mvp" again?
Nov 21 '05 #11
"" <a@b.com> schrieb:
| > That looks good but the "AddHandler" lines simply say "syntax error"
in
| > vb.net. I've added them to the top under the variable declarations
and
| > within the sub main but they always show syntax error.
| > [...]
| >> AddHandler ( _
| >> SystemEvents.SessionEnding, _
| >> AddressOf ShutDown.OnShuttingDown _
| >> )
|
| Remove the braces ('(', ')').

once again herf, it is you who needs to remove something...your head from
your ass. the syntax is NOT a problem. if you knew what the hell you were
talking about, you know the problem was *where* the op placed this code.


Again wrong. The code cannot be compiled because of the braces. You are
discrediting yourself.

From the VB.NET Language Specification:

| AddHandlerStatement ::=
| AddHandler Expression , Expression StatementTerminator
| RemoveHandlerStatement ::=
| RemoveHandler Expression , Expression StatementTerminator

BTW:

Rules of Conduct
<URL:http://www.microsoft.com/communities/conduct/default.mspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...

| Rules of Conduct
| <URL:http://www.microsoft.com/communities/conduct/default.mspx>

Rules of Conduct

Appropriate Language: The purpose of our communities is to exchange
technical information and expertise about Microsoft products. Please avoid
personal attacks, slurs, and profanity in your interactions.

fuck you, herf...you dumbass, third-world, wannabe programmer.

Relevance to Topics: Please make sure that your postings in newsgroups and
chats are relevant to the subject at hand. It is normal for some topics to
drift from the stated subject. However, to ensure maximum benefit for
everyone, we encourage you to keep your postings as close to the subject as
possible.

today, the sky is blue...pull your head out of you ass, herf, and maybe take
a look at it.

Advertising/Solicitation: These communities were created as a forum for
providing peer-to-peer assistance related to using Microsoft products and
services. We ask that you refrain from posting unsolicited advertisements
that do not pertain directly to the intended use and purpose of the
newsgroup or chat.

for the best kiddie-porn in town: mailto:hi**@qmx.at

Confidentiality: Please keep in mind that our communities are public spaces,
so don't post anything that you don't want the world to see. Credit card
numbers, product keys, and other confidential information, including
anything covered under a non-disclosure agreement (NDA), should not be
posted to a newsgroup, chat, or other community.

herf is one big nda for stupidity...that's ok, you can keep those secrets to
yourself as i don't care to have your special brand thereof replicated. and
now that i think of it, please don't involve yourself in copulation
either...the results could be disastrous.
Nov 21 '05 #13

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

Similar topics

5
by: Viper | last post by:
.... say, like MS Word opens another instance of himself when you open another document. If you close the first 'Word', the second document remains alive. I can't figure out how to do the same...
7
by: Nikki | last post by:
Hi, Can anybody help me, i want to prevent windows to close my winform of ..NET application, when user presses Alt+F4
4
by: sm mehta | last post by:
Hi, I have a web Application that must be licensed. When Customer buys 2 licensees for my application they can only have 2 copies open at a time. What I am doing right now is, I am storing No....
3
by: Denon | last post by:
How to trap browser close event in SERVER side? I read a lot of forum message, it talk about onclose(), onunload() and even onbeforeunload() event. However, all of theses are based on javascript...
5
by: Stan Sainte-Rose | last post by:
Hi, Which event is called when the user click on the close window icon (X) ? I want, when he clicks on this icon, to display a message before closing the form. If he replys by No, I don't want to...
1
by: bloodandrose | last post by:
Can you help me How to detect browser close event? Thanks
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
8
by: mattgcon | last post by:
I have a popup form within my application that I want to show for only about 10 seconds. On this form by the way has an AVI that plays. I want the form to popup on click of a button and close after...
4
by: Mike Scirocco | last post by:
I have an iframe that includes a button: <input type="button" value="close this window" onclick="window.close();" > I would like to detect the iframe close event from the parent window, I was...
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...
1
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...
0
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...
1
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.