c# - How to detect when Windows 8 goes to sleep or resumes -
i have app keeps connection alive server, if user walks away , tablet goes sleep, handle disconnect gracefully, , log in when user wakes tablet.
i've tried in putting following code in connection class, never fired.
application.current.suspending += this.onappsuspending; application.current.resuming += this.onappresuming;;
for desktop apps, can use systemevents.powermodechanged event know if windows going sleep state. don't know if works tablets too, can try it...
from msdn:
• resume operating system resume suspended state.
• statuschange power mode status notification event has been raised operating system. might indicate weak or charging battery, transition between ac power , battery, or change in status of system power supply.
• suspend operating system suspended.
systemevents.powermodechanged += onpowerchange; private void onpowerchange(object s, powermodechangedeventargs e) { switch ( e.mode ) { case powermodes.resume: break; case powermodes.suspend: break; } }
Comments
Post a Comment