locked
How to know my window is deactivated?

    Question

  • Say if I have a game and I want to pause the game when the user switch away to another full screen app, so it does not consume GPU or play music at the background, how do I do that? The ICoreWindow.Activated Event does not give information on whether the window is activated or deactivated, and the samples on MSDN seems like assume the event is only raised on activation, contrary to the documentation of the event. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Saturday, September 17, 2011 1:47 PM

Answers

  • It looks like there is a good example about suspension at http://blogs.microsoft.co.il/blogs/ranw/archive/2011/09/16/handling-application-states-on-windows-8.aspx.

    I am interested in deactivation within my own app too, so it looks like WindowActivatedEventArgs.WindowActivationState is what I need. I was unable to find the property because at the documentation page of ICoreWindow.Activated event, I was directed to the TypedEventHandler<TSender, TResult> delegate page instead of WindowActivatedEventArgs when I click on the WindowActivatedEventArgs link. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, September 19, 2011 1:15 AM

All replies

  • When your app is switched to the background it will be suspended (so it can't use GPU/CPU resources) and you will recieve a notification to allow you to save any state, which you have 5 seconds to do before the app suspends (if you fail to complete in this time Windows will crash the app). If the app is restored whilst still in memory it will just start being scheduled again and carry on as before (you can recieve a resume notification if needed). If the system requires the memory allocated to you application whilst it is in a suspended state it will be terminated without notice (which is why you should save state on suspend).

    I'd strongly recommend watching the Build presentation on Metro application lifecycles to better understand how this works: http://channel9.msdn.com/Events/BUILD/BUILD2011/APP-409T

     

    Sunday, September 18, 2011 10:48 PM
  • It looks like there is a good example about suspension at http://blogs.microsoft.co.il/blogs/ranw/archive/2011/09/16/handling-application-states-on-windows-8.aspx.

    I am interested in deactivation within my own app too, so it looks like WindowActivatedEventArgs.WindowActivationState is what I need. I was unable to find the property because at the documentation page of ICoreWindow.Activated event, I was directed to the TypedEventHandler<TSender, TResult> delegate page instead of WindowActivatedEventArgs when I click on the WindowActivatedEventArgs link. 



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, September 19, 2011 1:15 AM