Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have created services which is able to send mail via gmail.

i want use this same service who monitor my system for shutdown or log off ...

if any of above notify then it will send mail.

so how to get system shutdown notification in services.
Posted
Comments
SoMad 22-Feb-14 3:17am    
I don't think there is an actual System Shutdown notification, but the system will stop your service as part of the process and you could simply send an email whenever your service is being stopped.
However, I would not try to do that unless I really, really have to. You risk timing out because other services your mail feature relies on have been stopped before your service. If your service does not stop within a certain time, the system will simply kill it and the whole thing is useless.

Have you considered alternative behavior?

Soren Madsen

1 solution

You can attach an event handler to the SystemEvents.SessionEnding[^] event. Here is an example[^].
 
Share this answer
 
Comments
SoMad 22-Feb-14 4:16am    
Nifty. I did not know about that one (probably because I never really needed it). :thumbsup:

Soren Madsen
Maarten Kools 22-Feb-14 4:22am    
I know there is native message that is sent through the event loop for system shutdown, but I didn't know there was a .NET event either. Thanks for the 5 stars :)
SoMad 22-Feb-14 4:42am    
I don't always get around to voting answers up, but here I learned something, so... :)

Soren Madsen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900