By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,961 Members | 2,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,961 IT Pros & Developers. It's quick & easy.

SessionEnding Event stops

P: n/a
Hello everyone,

I'm listening to the SessionEnding event, so I can close my application
properly when Windows is shutting down.

I do some disposing and stuff if the event occurrs but windows doesn't
shutdown after that. Somehow my application cancels the shutdown.

It doesn't matter what I set in the Cancel Property of the
SessionEnding Event.

What am I doing wrong?
Thanks.

bye bembi

Sep 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
<bb*******@lycos.dewrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
[...]
I do some disposing and stuff if the event occurrs but windows doesn't
shutdown after that. Somehow my application cancels the shutdown.

It doesn't matter what I set in the Cancel Property of the
SessionEnding Event.

What am I doing wrong?
Well, for one...not posting the actual code in question? :) Seriously
though, it's hard to tell you what you're doing wrong if we don't know what
you're doing.

I've had no trouble using the SessionEnding event to cancel or to not cancel
the logoff/shutdown as I desire. I do recall that in at least one place,
the documentation had the sense of the Cancel property backwards. That is,
it said to set it to false in order to stop the logoff/shutdown from
happening, when in fact it's the opposite. But otherwise, it works just as
expected.

Pete
Sep 23 '06 #2

P: n/a
Hi,

well I tried both: set Cancel to true and false.
And basically if the SessionEnding event happens I do a dispose of my
application and then Environment.Exit()

bye bembi
Peter Duniho schrieb:
<bb*******@lycos.dewrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
[...]
I do some disposing and stuff if the event occurrs but windows doesn't
shutdown after that. Somehow my application cancels the shutdown.

It doesn't matter what I set in the Cancel Property of the
SessionEnding Event.

What am I doing wrong?

Well, for one...not posting the actual code in question? :) Seriously
though, it's hard to tell you what you're doing wrong if we don't know what
you're doing.

I've had no trouble using the SessionEnding event to cancel or to not cancel
the logoff/shutdown as I desire. I do recall that in at least one place,
the documentation had the sense of the Cancel property backwards. That is,
it said to set it to false in order to stop the logoff/shutdown from
happening, when in fact it's the opposite. But otherwise, it works just as
expected.

Pete
Sep 24 '06 #3

P: n/a
<bb*******@lycos.dewrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
well I tried both: set Cancel to true and false.
And basically if the SessionEnding event happens I do a dispose of my
application and then Environment.Exit()
Do you do that inside the SessionEnding handler? If so, then it sounds as
though you may be abnormally terminating your application before the handler
has a chance to return. Perhaps in that situation, the OS assumes that the
shutdown should be canceled since it never had a chance to get the actual
response from the SessionEnding handler.

You should be only using the SessionEnding event to provide feedback to the
OS as to whether a shutdown/logoff can safely occur, and possibly saving
some state. You can handle other cleanup in the SessionEnded (not
....Ending) event, and in there you need not do anything to explicitly end
your application (after returning from that event handler, the OS will most
likely forceably terminate your application anyway...don't expect any more
code to be able to run after that).

Pete
Sep 25 '06 #4

P: n/a
Hello again,

the problem is that my application doesn't get terminated from windows.
I have to do that myself.

And I never reach the SessionEnded event. Even if I remove the
Environment.Exit from the SessionEnding event.

bye bembi
Peter Duniho schrieb:
<bb*******@lycos.dewrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
well I tried both: set Cancel to true and false.
And basically if the SessionEnding event happens I do a dispose of my
application and then Environment.Exit()

Do you do that inside the SessionEnding handler? If so, then it sounds as
though you may be abnormally terminating your application before the handler
has a chance to return. Perhaps in that situation, the OS assumes that the
shutdown should be canceled since it never had a chance to get the actual
response from the SessionEnding handler.

You should be only using the SessionEnding event to provide feedback to the
OS as to whether a shutdown/logoff can safely occur, and possibly saving
some state. You can handle other cleanup in the SessionEnded (not
...Ending) event, and in there you need not do anything to explicitly end
your application (after returning from that event handler, the OS will most
likely forceably terminate your application anyway...don't expect any more
code to be able to run after that).

Pete
Sep 25 '06 #5

P: n/a
I found another clue.
If I never open a specific form in my application, windows shuts down
properly.
If I just call the Show and Hide of this form Windows doesn't shut down
any more.

Any idea?

bye bembi

Sep 25 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.