Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know when Windows is going into/out of sleep or Hibernate mode?

Tags:

Is it possible to subscribe to a Windows event that fires when Windows is going into or coming out of Sleep or Hibernate state?

I need my application to be made aware when the computer is going to sleep to do some cleanup and avoid timing issues when it comes out of sleep.

like image 516
Chris Thompson Avatar asked Oct 23 '08 02:10

Chris Thompson


People also ask

Is my computer sleeping or hibernating?

Sleep mode stores the documents and files you are operating into the RAM, using a small amount of power in the process. Hibernate mode essentially does the same thing, but saves the information to your hard disk, which allows your computer to be turned off completely and use no energy.

How do I know if hibernate is off or on?

In the search results list, right-click Command Prompt, and then select Run as Administrator. When you are prompted by User Account Control, select Continue. At the command prompt, type powercfg.exe /hibernate on , and then press Enter. Type exit, and then press Enter to close the Command Prompt window.

How do you see what is keeping Windows awake?

To do this, search for cmd again, and then right-click it and select Run as administrator. If any process or device is preventing your system from going into sleep mode, information about it will be displayed here.


1 Answers

Microsoft.Win32.SystemEvents.PowerModeChanged event will give you this information. This event is available in all variants of the .NET framework released by Microsoft so far.

like image 145
Jeff Yates Avatar answered Sep 19 '22 22:09

Jeff Yates