hibernate-mode

How do I gracefully handle hibernate/sleep modes in a winforms application?

孤街醉人 提交于 2019-12-06 17:18:03
问题 I am writing a windows form application in .net using C#. I am running into a problem that if my program is running when the computer goes into the sleep and/or hibernate state (I am not sure at this time which one, or if both, cause the problem), when the machine wakes up again the program just hangs. The only way to exit out of it is to kill the process from the task manager. This is, for obvious reasons, not the way I want the program to function. Even if I just shut the program down when

Can't catch sleep/suspend messages (winXP)

微笑、不失礼 提交于 2019-11-27 16:45:57
问题 My app needs to block sleep/hibernate mode. I have the code in place, but after successfully catching the WM_POWERBROADCAST message, neither PBT_APMQUERYSUSPEND nor PBT_APMQUERYSTANDBY are being caught successfully. Interestingly, the PBT_APMRESUMECRITICAL and PBT_APMRESUMEAUTOMATIC messages are being caught by my app. Bottom line question: is there any reason why my app would fail to catch the standby/suspend messages, but succeed in catching the resume messages? This Q&A [stackoverflow.com]

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

半腔热情 提交于 2019-11-27 13:34:18
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. 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. In .NET, use the PowerModeChanged event. In Win32, use the WM_POWERBROADCAST message. You can monitor Win32_PowerManagementEvent WMI event Not sure

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

混江龙づ霸主 提交于 2019-11-26 16:27:16
问题 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. 回答1: 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. 回答2: In .NET, use the PowerModeChanged