SessionEnding Event stops

B

bbembi_de

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
 
P

Peter Duniho

[...]
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
 
B

bbembi_de

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 said:
[...]
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
 
P

Peter Duniho

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
 
B

bbembi_de

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
 
B

bbembi_de

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
 

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