locked
Detect when computer goes to Stand by RRS feed

  • Question

  • How can I detect when the computer goes to stand by or hibernate? I am making a program that doesn't use the system time but its own internal time, but when it goes to stand by or hibernate, the clock stops ticking, and it becomes way off.
    Monday, September 6, 2010 3:59 PM

Answers

  • Check out the Microsoft.Win32.SystemEvents static class...specifically, the PowerModeChanged event:

    http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx

    You can also subscribe to the SystemEvents.SessionSwitch event which may also be helpful if you need to determine when the user locks or unlocks the workstation.

    http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionswitch%28v=VS.100%29.aspx

    HTH,

    ShaneB

    • Marked as answer by TIMOTHEVS1 Tuesday, September 7, 2010 12:01 PM
    Monday, September 6, 2010 4:22 PM

All replies

  • Check out the Microsoft.Win32.SystemEvents static class...specifically, the PowerModeChanged event:

    http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx

    You can also subscribe to the SystemEvents.SessionSwitch event which may also be helpful if you need to determine when the user locks or unlocks the workstation.

    http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionswitch%28v=VS.100%29.aspx

    HTH,

    ShaneB

    • Marked as answer by TIMOTHEVS1 Tuesday, September 7, 2010 12:01 PM
    Monday, September 6, 2010 4:22 PM
  • Thanks. It works now, and thank you for telling me about the SessionSwitch event. I would have had to figure it out myself if you didn't tell me.
    Tuesday, September 7, 2010 12:01 PM