Building metro style        applications on Windows 8          using background task                                      ...
ITCamp 2012 sponsors                                                       Mobile &                                       ...
Agenda                                                                     Mobile &                                       ...
Why we need background tasks                                               Mobile &                                       ...
Why we need background tasks                                               Mobile &                                       ...
Windows Metro Applications                                                 Mobile &                                       ...
Background tasks                                                           Mobile &                                       ...
Background task types                                                      Mobile &                                       ...
When to use them                                                           Mobile &                                       ...
Background task triggers                                                         Mobile &                                 ...
Background task triggers                                                         Mobile &                                 ...
Background task triggers                                                         Mobile &                                 ...
Background task conditions                                                 Mobile &                                       ...
Background task infrastructure                                                                 Mobile &                   ...
Where a background task run                                                        Mobile &                               ...
Where a background task run                                                          Mobile &                             ...
Notifications                                                              Mobile &                                       ...
Basic steps to implement                                                     Mobile &                                     ...
Base classes                                                               Mobile &                                       ...
Live demo                                                                  Mobile &                                       ...
CPU resource constrains                                                          Mobile &                                 ...
Network resource constraints                                                               Mobile &                       ...
Tips and tricks                                                            Mobile &                                       ...
Best practices                                                             Mobile &                                       ...
@   itcampro   # itcamp12   Premium conference on Microsoft technologies
THE END                                                           Radu Vunvulea                                           ...
Upcoming SlideShare
Loading in …5
×

ITCamp 2012 - Radu Vunvulea - Building metro style applications on Windows 8 using background tasks

571 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
571
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ITCamp 2012 - Radu Vunvulea - Building metro style applications on Windows 8 using background tasks

  1. 1. Building metro style applications on Windows 8 using background task Radu Vunvulea iQuest http://vunvulearadu.blogspot.com Twitter: @RaduVunvulea@ itcampro # itcamp12 Premium conference on Microsoft technologies
  2. 2. ITCamp 2012 sponsors Mobile & Development@ itcampro # itcamp12 Premium conference on Microsoft technologies
  3. 3. Agenda Mobile & Development• Why we need background tasks• Base concepts• When to use them• Triggers• Conditions• Notifications• Demo• Tips and Tricks• Q&A@ itcampro # itcamp12 Premium conference on Microsoft technologies
  4. 4. Why we need background tasks Mobile & Development• What happens with classic applications?• Where Windows Services vanish?• Why do I need background tasks?@ itcampro # itcamp12 Premium conference on Microsoft technologies
  5. 5. Why we need background tasks Mobile & Development• What happens with classic applications?• Where Windows Services vanish?• Why do I need background tasks?@ itcampro # itcamp12 Premium conference on Microsoft technologies
  6. 6. Windows Metro Applications Mobile & Development• Similar to Windows Phone applications• Only threads from the current application (foreground) are running@ itcampro # itcamp12 Premium conference on Microsoft technologies
  7. 7. Background tasks Mobile & Development• Running code in background• The background task doesn’t depend on application state• Small work items• No interaction with UI• What we gain: – Smooth user experience – Long battery life@ itcampro # itcamp12 Premium conference on Microsoft technologies
  8. 8. Background task types Mobile & Development• System – Playback manager – Push notification – Background transfer API • Upload files • Download files• User-defined – Almost any type of custom action@ itcampro # itcamp12 Premium conference on Microsoft technologies
  9. 9. When to use them Mobile & Development• Receive chat message• Process an incoming SMS• Download email• Display a toast notification• Execute action when something changes• Display UI, play music• Process photos• Index data@ itcampro # itcamp12 Premium conference on Microsoft technologies
  10. 10. Background task triggers Mobile & DevelopmentControlChannelTrigger ServicingCompleteInternetAvailable SessionConnectedInternetNotAvailable SessionDisconnectedLockScreenApplicationAdded SessionStartLockScreenApplicationRemoved SmsReceivedMaintenanceTrigger TimeTriggerNetworkNotificationChannelReset TimeZoneChangeNetworkStateChange UserAwayOnlineIdConnectedStateChange UserPresentPushNotificationTrigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  11. 11. Background task triggers Mobile & DevelopmentControlChannelTrigger ServicingCompleteInternetAvailable SessionConnectedInternetNotAvailable SessionDisconnectedLockScreenApplicationAdded SessionStartLockScreenApplicationRemoved SmsReceivedMaintenanceTrigger TimeTriggerNetworkNotificationChannelReset TimeZoneChangeNetworkStateChange UserAwayOnlineIdConnectedStateChange UserPresentPushNotificationTrigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  12. 12. Background task triggers Mobile & Development• Some triggers require the application to be on the lock screenControlChannelTrigger ServicingCompleteInternetAvailable SessionConnectedInternetNotAvailable SessionDisconnectedLockScreenApplicationAdded SessionStartLockScreenApplicationRemoved SmsReceivedMaintenanceTrigger TimeTriggerNetworkNotificationChannelReset TimeZoneChangeNetworkStateChange UserAwayOnlineIdConnectedStateChange UserPresentPushNotificationTrigger• An application can register to be notified when it is added or removed from lock screen@ itcampro # itcamp12 Premium conference on Microsoft technologies
  13. 13. Background task conditions Mobile & Development• 0..n conditions can be added to each background task• Only when all conditions are met, the given task is launched Background task condition The condition that must be satisfied InternetAvailable The Internet must be available. InternetNotAvailable The Internet must be unavailable. SessionConnected The session must be connected. SessionDisconnected The session must be disconnected. UserNotPresent The user must be away. UserPresent The user must be present.@ itcampro # itcamp12 Premium conference on Microsoft technologies
  14. 14. Background task infrastructure Mobile & Development Application System 4. Launch background task System My Application 3. Fire trigger 2. Register class with triggers Control Channel Control Channel 1. Register trigger Trigger Trigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  15. 15. Where a background task run Mobile & Development Application BackgroundTaskHost.exe Application or BackgroundTaskHost.exe@ itcampro # itcamp12 Premium conference on Microsoft technologies
  16. 16. Where a background task run Mobile & Development TimeTrigger SystemTrigger ControlChannelTrigger MaintenanceTrigger Application BackgroundTaskHost.exe Application or BackgroundTaskHost.exe PushNotificationTrigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  17. 17. Notifications Mobile & Development• The following notification can send to the base application: – Progress notifications – Completion notifications – Exceptions thrown• A background task can be receive cancellations notifications only from operating system – The task have 5s to save his state until the system close the application@ itcampro # itcamp12 Premium conference on Microsoft technologies
  18. 18. Basic steps to implement Mobile & Development• JavaScript – Add a new dedicated worker file• C#/C++ – Add a new Windows 8 Metro style app class library project to the solution. – Add a reference to the newly added class library project in the main Windows 8 Metro style app project that registers the background tasks. – Ensure that the output type of the class library is Winmd and not DLL. – Add the required manifest entries for background tasks to the Windows 8 Metro style app – Seal the class that implements the IBackgroundTask@ itcampro # itcamp12 Premium conference on Microsoft technologies
  19. 19. Base classes Mobile & Development• IBackgroundTask – used to implement the background task• IBackgroundTaskInstance – provides access to a background task instance• BackgroundTaskDeferral – used for async calls from background task• BackgroundTaskBuilder – used to register a background task• BackgroundTaskRegistration – a background class that was registered• BackgroundTaskRegistration.AllTasks – get a list of tasks of the current application@ itcampro # itcamp12 Premium conference on Microsoft technologies
  20. 20. Live demo Mobile & Development@ itcampro # itcamp12 Premium conference on Microsoft technologies
  21. 21. CPU resource constrains Mobile & Development• Limited CPU time for each application• Use BackgroundTaskDeferral for async calls CPU resource quota Refresh period Lock screen app 2 CPU seconds 15 minutes Non-lock screen app 1 CPU second 2 hours• Restrictions are applied on AC power also• Exceptions: – Control channel – Push notifications@ itcampro # itcamp12 Premium conference on Microsoft technologies
  22. 22. Network resource constraints Mobile & Development• Different network interfaces require different amount of energy• Wi-Fi resource constraints: Average Data throughput, in megabytes (MB) Data throughput, in MB, for non-lock throughput for lock screen apps screen apps Every 15” Per day Every 2 hours Per day 1 Mbps 0.1875 18 0.25 3 10 Mbps 1.875 180 2.5 30 20 Mbps 3.75 360 5 60• On AC power there is no limitation for Wi-Fi network@ itcampro # itcamp12 Premium conference on Microsoft technologies
  23. 23. Tips and tricks Mobile & Development• TimeTrigger minimum time interval is 15 minutes• Progress and Complete handlers needs to be associated each time when application start• BackgroundTaskDeferral can be used for async calls• Don’t rely on global pool when all allocated CPU time was used• When a background task is suspended a message is logged in the Event Viewer.• Share data between application and background task only by files or State Manager@ itcampro # itcamp12 Premium conference on Microsoft technologies
  24. 24. Best practices Mobile & Development• Design background tasks to be short lived• Use persistent storage to share data between the background task and the app• Verify if the app needs to be on the lock screen• Do not display UI other than toast, tiles or badges from a background task.• Do not rely on user interaction in background tasks@ itcampro # itcamp12 Premium conference on Microsoft technologies
  25. 25. @ itcampro # itcamp12 Premium conference on Microsoft technologies
  26. 26. THE END Radu Vunvulea iQuest http://vunvulearadu.blogspot.com Twitter: @RaduVunvulea@ itcampro # itcamp12 Premium conference on Microsoft technologies

×