Answered by:
How to detect system sleep or hibernate in metro app?

Question
-
We have a metro app newly built which has low level library will track user's location data. If system is in "SLEEP" or "HIBERNATE" mode. We need to
stop the low level threads, and resume them when system resumes.
Is there some way to track system power status in C++/CX?
Friday, March 16, 2012 3:02 AM
Answers
-
Hi Dong Yi,
According I ask MSFT via another thread http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/9a6f9c1b-49ea-485b-9f2b-6cce840d84b5/
Gearard point out some direction the "debugger" is why you could not get correct "suspend" and "resume" event trigger on your app.
So I do some test and summarize my result as follows:
- When leave app about 5 sec or trigger another app about 5 sec, the "suspend" event will called.
- "Suspends"/"Resume" event will trigger automatically when you not attach debugger on release build. See "Star without Debugging" on "debug" tab.
- If you using debugger, you only trigger "suspend" manually.
- Sleep/Hibernate will trigger "Suspend" if your app is release version without debugger attach.
I hope it helps, since it already resolve my question for long time.
Evan Lin
- Proposed as answer by Todd Chen Thursday, March 22, 2012 5:30 AM
- Marked as answer by Yi Feng Li Wednesday, April 4, 2012 3:18 AM
Wednesday, March 21, 2012 6:33 AM
All replies
-
Hi,
According build session "Fundamentals of Metro style apps: how and when your app will run" (http://channel9.msdn.com/Events/BUILD/BUILD2011/APP-409T")
Before system query event is arrived, metro app should goes to "Suspend" first.
So you should handle your app work well when your metro app is under suspend state.
See more on
http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx
Friday, March 16, 2012 11:21 AM -
thanks for your reply. I have already tested this...
I tried to register "suspend" and "resume" event handler. But when system hibernates then resumes they are not invoked.
However they can be invoked when I press "suspend the application" or "resume the application" button in VS.
- Edited by Dong, Yi Saturday, March 17, 2012 3:01 AM
Saturday, March 17, 2012 3:01 AM -
Someone has tested suspend/resume callback when system sleep/hibernate?Wednesday, March 21, 2012 1:13 AM
-
Metro app has only 3 states.. running, suspended, not running..
You should be register the suspending event handler like this section.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465115.aspx
And you can catch the event's type through SuspendingEventArgs maybe.
void MainPage::App_Suspending(Object^ sender, SuspendingEventArgs^ e)
Good luck.
Wednesday, March 21, 2012 2:11 AM -
What steps are you taking to hibernate the system? The events are firing as I would expect when using the charm bar to put my laptop to sleep or by using the physical power button. I'm using the Media capture using webcam sample with a few modifications to the ::Suspending and ::Resuming methods to test the functionality. I am launching it from the Start Screen and putting the system to sleep with the app in the forground.
David Lamb
- Edited by DavidLambMicrosoft employee, Moderator Wednesday, March 21, 2012 5:09 AM
Wednesday, March 21, 2012 5:02 AMModerator -
Hi Dong Yi,
According I ask MSFT via another thread http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/9a6f9c1b-49ea-485b-9f2b-6cce840d84b5/
Gearard point out some direction the "debugger" is why you could not get correct "suspend" and "resume" event trigger on your app.
So I do some test and summarize my result as follows:
- When leave app about 5 sec or trigger another app about 5 sec, the "suspend" event will called.
- "Suspends"/"Resume" event will trigger automatically when you not attach debugger on release build. See "Star without Debugging" on "debug" tab.
- If you using debugger, you only trigger "suspend" manually.
- Sleep/Hibernate will trigger "Suspend" if your app is release version without debugger attach.
I hope it helps, since it already resolve my question for long time.
Evan Lin
- Proposed as answer by Todd Chen Thursday, March 22, 2012 5:30 AM
- Marked as answer by Yi Feng Li Wednesday, April 4, 2012 3:18 AM
Wednesday, March 21, 2012 6:33 AM -
thanks for all, i will try againFriday, March 23, 2012 12:25 PM
-
Hi Guys,
Look like Dong, Yi is right.
'thanks for your reply. I have already tested this... I tried to register "suspend" and "resume" event handler. But when system hibernates then resumes they are not invoked. However they can be invoked when I press "suspend the application" or "resume the application" button in VS.'
I have same issue, very simple to reproduce in laptop:
1. Subscribe to 'suspend/resume' events
2. Launch your app.
3. Close your laptop
4. Open laptop again, nothing happen. Sleep/Hibernate WILL NOT trigger 'suspend' events!
I am sit on this problem already 2 days. Any another solution?
Thanks
- Rost
;-)Rost
Wednesday, August 1, 2012 12:13 AM -
Hi, I met the same problem "But when system hibernates then resumes they are not invoked",
Is this resolved or have an officail response?
Thursday, October 11, 2012 2:37 AM -
Hi Mountain2012,
The marked answer is correct: the debugger prevents apps from suspending (otherwise you couldn't debug them).
If you are having trouble with suspend/resume when not debugging then please post your question in a new thread.
--Rob
Thursday, October 11, 2012 3:58 AMModerator -
Thanks Rob.
I run the app in release mode, not debugging.
I find another page, it says system sleep/hibernate will not trigger suspend event. This answer my question.
Thursday, October 11, 2012 6:41 AM