driis
driis

Reputation: 164291

Detect system standby/sleep/hibernate from .NET Windows Service?

In a Windows Service, I need to detect when the computer goes into sleep and when it wakes up, and run some code on these events. This needs to be done for sleep, standby and hibernate power modes.

How do I do that ?

Upvotes: 5

Views: 4711

Answers (2)

Hans Passant
Hans Passant

Reputation: 941465

Override the ServiceBase.OnPowerEvent() method.

Upvotes: 9

Sergej Andrejev
Sergej Andrejev

Reputation: 9413

I'm not sure because I have never did it myself but recently I came accross OnSessionChange method. I can't promise it allows to catch sleep event, but may be studying it's documentation in MSDN or elswere can help you.

http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.canhandlesessionchangeevent.aspx

Upvotes: 1

Related Questions