power-state

What is the proper way to have a Windows service stop and start gracefully when suspending/resuming a PC?

依然范特西╮ 提交于 2019-12-12 10:37:41
问题 I need to stop our Windows service when a PC is powered down into Suspend mode and restart it when the PC is resumed again. What is the proper way to do this? 回答1: You should override the ServiceBase.OnPowerEvent Method. protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus) { if (powerStatus.HasFlag(PowerBroadcastStatus.QuerySuspend)) { } if (powerStatus.HasFlag(PowerBroadcastStatus.ResumeSuspend)) { } return base.OnPowerEvent(powerStatus); } The PowerBroadcastStatus

Detecting screen monitor Power State change in c++

馋奶兔 提交于 2019-12-10 20:41:46
问题 I have a Windows message loop. I need to detect when the screen powers back up. Is there a windows message? detect power state change contains the C# way, I need the C++ way, using win32 API. If there isn't a Windows message, how do I poll for screen monitor power state? 回答1: There is a Windows message WM_POWERBROADCAST. There Windows API has a lot of support for power management. See the section on Windows Power Management at MSDN for the details. 回答2: For newer windows versions (starting

Detecting the device being plugged in

て烟熏妆下的殇ゞ 提交于 2019-11-27 08:46:37
I would like to be able to detect whether or not the device is plugged in. I would like to be able to just query that the same way we can do for the connectivity state. Is that possible or do I need to create a broadcast receiver that listens for the battery events? Apparently the ACTION_BATTERY_CHANGED is a "sticky broadcast" which means you can register for it and receive it any time after it has been broadcast. To get the plugged state you can do something like: public void onCreate() { BroadcastReceiver receiver = new BroadcastReceiver() { public void onReceive(Context context, Intent

Detecting the device being plugged in

白昼怎懂夜的黑 提交于 2019-11-26 17:46:57
问题 I would like to be able to detect whether or not the device is plugged in. I would like to be able to just query that the same way we can do for the connectivity state. Is that possible or do I need to create a broadcast receiver that listens for the battery events? 回答1: Apparently the ACTION_BATTERY_CHANGED is a "sticky broadcast" which means you can register for it and receive it any time after it has been broadcast. To get the plugged state you can do something like: public void onCreate()