PLM and Background Tasks by Jason Fox

681 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

PLM and Background Tasks by Jason Fox

  1. 1. demo
  2. 2. Apps do not get notified when they are getting terminated
  3. 3. Registering for Suspend and Resume is Easy //Register for the Suspending event and call suspendingHandler when received Windows.UI.WebUI.WebUIApplication.addEventListener("suspending", suspendingHandler); //Handle the suspending event and save the current user session using WinJS sessionState function suspendingHandler(eventArgs) { //We are getting suspended } //Register for the Resuming event and call resumingHandler when received Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", resumingHandler); function resumingHandler( ) { //We are getting resumed, in general do nothing }
  4. 4. Registering for Suspend and Resume is Easy // Register for the Suspending event and call OnSuspending when received // Handle the suspending event and save the current user session using WinJS sessionState void async var //TODO: Save application state and stop any background activity } // Register for the Resuming event and call OnResuming when received void object object { // We are getting resumed, in general do nothing }
  5. 5. Scenario You should:
  6. 6. User Launches App Splash screen
  7. 7. demo
  8. 8. Multiple per app System Trigger Leaving blank: BackgroundTaskHost.exe WinRT Component
  9. 9. Yourapp.exe MyBackgroundTask WinRTComponent Create Call Run() BackgroundTaskHost.exe Windows
  10. 10. Example System Trigger Register on User Login using Windows.ApplicationModel.Background; // Specify the trigger IBackgroundTrigger trigger = new SystemTrigger(SystemTriggerType.SessionConnected, false); Create user login trigger Associate trigger with app code // Associate app code with the trigger BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyApp.Background.RegisterForUserLogin"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “OnUserPresent"; Register // Register the task for background execution trigger IBackgroundTaskRegistration taskRegistration = taskBuilder.Register();
  11. 11. Example System Trigger Background execution on User Login using Windows.ApplicationModel.Background; namespace MyApp.Background { public sealed class RegisterForUserLogin: IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Your app code } } }
  12. 12. Trigger Lock screen Description UserPresent X User becomes present (touches screen, keyboard, mouse) UserAway X User becomes absent or system idle timer expires. SessionConnected X User logs in. ControlChannelReset X Control channel is reset InternetAvailable Internet becomes available NetworkStateChange Change in connection state (cost, network) ServicingComplete App update has finished OnlineIdConnectedStateChange Microsoft account connected to logon account has changed. LockScreenApplicationAdded An app has been added to the lock screen LockScreenApplicationRemoved An app has been removed from the lock screen TimeZoneChange The system time zone has changed SmsReceived SMS message received by mobile broadband device. BackgroundWorkCostChange X the cost of background work changes
  13. 13. CPU resource quota Lock screen app Non-lock screen app Refresh period
  14. 14. demo
  15. 15. System Condition Description InternetAvailable/InternetNotAvailable Availability of Internet connectivity UserPresent / UserNotPresent Presence of user SessionConnected / SessionDisconnected User’s logged-on status FreeNetworkAvailable Availability of free internet BackgroundWorkCostNotHigh Only when on AC
  16. 16. var t = new SystemTrigger(SystemTriggerType.NetworkStateChange, false); var btb = new BackgroundTaskBuilder() { TaskEntryPoint = "BGComponent.BTC", Name = "NetworkState Changed" }; btb.SetTrigger(t); SystemCondition c = new SystemCondition(SystemConditionType.UserPresent); btb.AddCondition(c); BackgroundTaskRegistration task = btb.Register();
  17. 17. Completed Yourapp.exe Progress MyBackgroundTask WinRTComponent Cancel BackgroundTaskHost.exe Cancel Windows
  18. 18. demo
  19. 19. • Hardware includes low-power DRAM, busses, and devices • Always connected to the internet • App experiences are always fresh and up to date • Transitions instantly between on and off states (phone-like behavior) Requires very low idle power to enable Connected Standby
  20. 20. • How does this work in connected standby? Mobile broadband Network (e.g. 3G, 4G, LTE, etc.) Connectivity • Nothing special, one model to stay connected. • Need a hardware slot
  21. 21. • Implement a Cancel handler. Cancel all outstanding tasks by using CancelationTokenSource
  22. 22. Longer Battery Life Always Reachable Apps
  23. 23. http://go.microsoft.com/fwlink/?LinkID=227329&clcid=0x409 http://msdn.microsoft.com/en-us/library/windows/apps/hh452975.aspx
  24. 24. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION

×