Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Windows services behave when entering/waking up from sleep or hibernate modes?

I have a service written in C# that does not seem to come down cleanly when the computer enters sleep mode. The user needs to manually stop and restart the service to retain functionality. I know what the issue is but I am not sure where to fix it. How do Windows services behave when going into/come out of sleep and hibernate?

like image 397
Bender the Greatest Avatar asked Jul 06 '12 17:07

Bender the Greatest


1 Answers

How do services react to power events? Really, it depends.

In your service you can handle the hibernate/suspend/etc events by handling it in your service

  protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
  { 
     //do stuff here
  }
like image 116
hometoast Avatar answered Sep 28 '22 10:09

hometoast