none
Delay a standby query RRS feed

  • Question

  • Hello everybody,

    It is possible to take note of the time of standby and wake up, like this :

    		static void Main(string[] args)
    		{
    			SystemEvents.PowerModeChanged += OnPowerModeChanged;
                    }
    
    		private static void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e)
    		{
    			Console.WriteLine("{0:HH\\:mm\\:ss} : {1}", DateTime.Now, e.Mode.ToString());
    		}

    But in PowerModeChangedEventArgs, I see no property to postpone the standby.

    I should like to defrag the disk, and launch the standby again once the defrag is done.

    Is there any more appropriate event ?

    Monday, July 15, 2019 3:25 PM

Answers

  • Hello Gloops,

    This forum is for "Discuss use of system messages about power management status, sleep transitions, and other aspects of managing power consumption at the application level." Refer to "Power Management Functions".

    So for win32 application, there is a PBT_APMSUSPEND event will notifies applications that the computer is about to enter a suspended state. "A window receives this event through the WM_POWERBROADCAST message. An application should process this event by completing all tasks necessary to save data. The system allows approximately two seconds for an application to handle this notification. If an application is still performing operations after its time allotment has expired, the system may interrupt the application."

    Or if you are developing application based on .NET API I can move your question to .NET forum for more professional support.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Gloops Tuesday, July 16, 2019 6:22 AM
    Tuesday, July 16, 2019 1:45 AM
  • Hello,

    Thank you for your answer, it helped me find that cancelling a standby request is obtained by

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); [FlagsAttribute] public enum EXECUTION_STATE : uint { ES_AWAYMODE_REQUIRED = 0x00000040, ES_CONTINUOUS = 0x80000000, ES_DISPLAY_REQUIRED = 0x00000002, ES_SYSTEM_REQUIRED = 0x00000001 // Legacy flag, should not be used. // ES_USER_PRESENT = 0x00000004 } SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);

    // to be placed in the main function

    For the moment being I tested that on Windows 10, on my development machine, but according to the documentation there should be no problem on Vista. The screen is set off, but moving the mouse sets it on again.

    I should have said that cancelling a standby request is an aspect of managing power consumption, no ?

    Supposing I have a bad surprise when using that further, what forum would you advise me ?



    • Marked as answer by Gloops Tuesday, July 16, 2019 6:22 AM
    • Edited by Gloops Tuesday, July 16, 2019 6:35 AM
    Tuesday, July 16, 2019 6:22 AM

All replies

  • Hello Gloops,

    This forum is for "Discuss use of system messages about power management status, sleep transitions, and other aspects of managing power consumption at the application level." Refer to "Power Management Functions".

    So for win32 application, there is a PBT_APMSUSPEND event will notifies applications that the computer is about to enter a suspended state. "A window receives this event through the WM_POWERBROADCAST message. An application should process this event by completing all tasks necessary to save data. The system allows approximately two seconds for an application to handle this notification. If an application is still performing operations after its time allotment has expired, the system may interrupt the application."

    Or if you are developing application based on .NET API I can move your question to .NET forum for more professional support.

    Best regards,

    Rita


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Gloops Tuesday, July 16, 2019 6:22 AM
    Tuesday, July 16, 2019 1:45 AM
  • Hello,

    Thank you for your answer, it helped me find that cancelling a standby request is obtained by

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); [FlagsAttribute] public enum EXECUTION_STATE : uint { ES_AWAYMODE_REQUIRED = 0x00000040, ES_CONTINUOUS = 0x80000000, ES_DISPLAY_REQUIRED = 0x00000002, ES_SYSTEM_REQUIRED = 0x00000001 // Legacy flag, should not be used. // ES_USER_PRESENT = 0x00000004 } SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_AWAYMODE_REQUIRED);

    // to be placed in the main function

    For the moment being I tested that on Windows 10, on my development machine, but according to the documentation there should be no problem on Vista. The screen is set off, but moving the mouse sets it on again.

    I should have said that cancelling a standby request is an aspect of managing power consumption, no ?

    Supposing I have a bad surprise when using that further, what forum would you advise me ?



    • Marked as answer by Gloops Tuesday, July 16, 2019 6:22 AM
    • Edited by Gloops Tuesday, July 16, 2019 6:35 AM
    Tuesday, July 16, 2019 6:22 AM