Checking for logout when closing a form?

A

Andy Pickering

I've written an app that minimises to the system tray when the 'close'
button is clicked (I'm setting the Cancel flag in my formname_Closing event
handler). This works fine until you try to logout of Windows - the logout
is unable to stop my app! Is there any way to check whether the user is
logging out/Windows is shutting down - or am I barking up the wrong tree?

Any pointers gratefully received.

Andy
 
D

Diggers

Odd!!!,

Can I just check, are you saying that if you shutdown windows it works
but not when you log off, or neither works.

Simon
 
A

Andy Pickering

Both logout and shutdown don't complete until I exit my app! All I'm doing
in my form's Closing event handler is setting the Cancel flag to True and
then calling the Hide() method. I would have thought that Windows closing
down or logging out would have automatically 'overruled' this....
 
D

Diggers

Ah ok,

Setting the CancelEventArgs.Cancel to true will cancel closing the
form. Maybe its got to do with the fact that windows tries to close it,
you don't let Windows do that and then Hide the form (which of course
means its still running). Is there any reason to set the Cancel flag to
true and if so (for example you need to do some cleaning up first), do
your cleanup and then Close the form instead of hiding it.

Make sense?

Simon Rigby
 
A

Andy Pickering

Simon - thanks for the response.

The idea was that when the user clicks the form's close button, the app
minimises to the system tray - a bit like MSN Messenger. To implement this
I added the 'Closing' event handler (I was hoping this would work similar to
the old 'QueryUnload' event from my VB6 days....). In operation, it works
fine - it just has this unfortunate side effect!
 
D

Diggers

ah of course, yes sorry you did mention that.

Hmm, I'll have a play and get back to you.

Simon
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

Hello, Andy:

Maybe you can handle the Microsoft.Win32.SystemEvents.SessionEnding event to know wheter the system is shutting down.
In the documentation for this event there is a sample of how to override the WndProc to achieve the same functionality.

Regards.


"Andy Pickering" <[email protected]> escribió en el mensaje | I've written an app that minimises to the system tray when the 'close'
| button is clicked (I'm setting the Cancel flag in my formname_Closing event
| handler). This works fine until you try to logout of Windows - the logout
| is unable to stop my app! Is there any way to check whether the user is
| logging out/Windows is shutting down - or am I barking up the wrong tree?
|
| Any pointers gratefully received.
|
| Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top