ITCamp 2012 - Radu Vunvulea - Building metro style applications on Windows 8 using background tasks
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

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

on

  • 706 views

 

Statistics

Views

Total Views
706
Views on SlideShare
706
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 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. ITCamp 2012 sponsors Mobile & Development@ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 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. 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. 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. 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. 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. 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. 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. Background task triggers Mobile & DevelopmentControlChannelTrigger ServicingCompleteInternetAvailable SessionConnectedInternetNotAvailable SessionDisconnectedLockScreenApplicationAdded SessionStartLockScreenApplicationRemoved SmsReceivedMaintenanceTrigger TimeTriggerNetworkNotificationChannelReset TimeZoneChangeNetworkStateChange UserAwayOnlineIdConnectedStateChange UserPresentPushNotificationTrigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 11. Background task triggers Mobile & DevelopmentControlChannelTrigger ServicingCompleteInternetAvailable SessionConnectedInternetNotAvailable SessionDisconnectedLockScreenApplicationAdded SessionStartLockScreenApplicationRemoved SmsReceivedMaintenanceTrigger TimeTriggerNetworkNotificationChannelReset TimeZoneChangeNetworkStateChange UserAwayOnlineIdConnectedStateChange UserPresentPushNotificationTrigger@ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 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. 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. 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. Where a background task run Mobile & Development Application BackgroundTaskHost.exe Application or BackgroundTaskHost.exe@ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 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. 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. 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. 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. Live demo Mobile & Development@ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 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. 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. 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. 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. @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 26. THE END Radu Vunvulea iQuest http://vunvulearadu.blogspot.com Twitter: @RaduVunvulea@ itcampro # itcamp12 Premium conference on Microsoft technologies