SlideShare a Scribd company logo
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
Mobile &
ITCamp 2012 sponsors                                                       Development




@   itcampro   # itcamp12   Premium conference on Microsoft technologies
Mobile &
Agenda                                                                     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
Mobile &
Why we need background tasks                                               Development


• What happens with classic applications?

• Where Windows Services vanish?

• Why do I need background tasks?




@   itcampro   # itcamp12   Premium conference on Microsoft technologies
Mobile &
Why we need background tasks                                               Development


• What happens with classic applications?

• Where Windows Services vanish?

• Why do I need background tasks?




@   itcampro   # itcamp12   Premium conference on Microsoft technologies
Mobile &
Windows Metro Applications                                                 Development


• Similar to Windows Phone applications
• Only threads from the current application
  (foreground) are running




@   itcampro   # itcamp12   Premium conference on Microsoft technologies
Mobile &
Background tasks                                                           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
Mobile &
Background task types                                                      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
Mobile &
When to use them                                                           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
Mobile &
Background task triggers                                                         Development




ControlChannelTrigger                        ServicingComplete
InternetAvailable                            SessionConnected
InternetNotAvailable                         SessionDisconnected
LockScreenApplicationAdded                   SessionStart
LockScreenApplicationRemoved                 SmsReceived
MaintenanceTrigger                           TimeTrigger
NetworkNotificationChannelReset              TimeZoneChange
NetworkStateChange                           UserAway
OnlineIdConnectedStateChange                 UserPresent
PushNotificationTrigger




@   itcampro        # itcamp12    Premium conference on Microsoft technologies
Mobile &
Background task triggers                                                         Development




ControlChannelTrigger                        ServicingComplete
InternetAvailable                            SessionConnected
InternetNotAvailable                         SessionDisconnected
LockScreenApplicationAdded                   SessionStart
LockScreenApplicationRemoved                 SmsReceived
MaintenanceTrigger                           TimeTrigger
NetworkNotificationChannelReset              TimeZoneChange
NetworkStateChange                           UserAway
OnlineIdConnectedStateChange                 UserPresent
PushNotificationTrigger




@   itcampro        # itcamp12    Premium conference on Microsoft technologies
Mobile &
Background task triggers                                                         Development

• Some triggers require the application to be on the lock screen

ControlChannelTrigger                        ServicingComplete
InternetAvailable                            SessionConnected
InternetNotAvailable                         SessionDisconnected
LockScreenApplicationAdded                   SessionStart
LockScreenApplicationRemoved                 SmsReceived
MaintenanceTrigger                           TimeTrigger
NetworkNotificationChannelReset              TimeZoneChange
NetworkStateChange                           UserAway
OnlineIdConnectedStateChange                 UserPresent
PushNotificationTrigger

• An application can register to be notified when it is added or removed
  from lock screen

@   itcampro    # itcamp12        Premium conference on Microsoft technologies
Mobile &
Background task conditions                                                 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
Mobile &
Background task infrastructure                                                                 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
Mobile &
Where a background task run                                                        Development




                   Application                         BackgroundTaskHost.exe




                                      Application or
                                 BackgroundTaskHost.exe




@   itcampro   # itcamp12           Premium conference on Microsoft technologies
Mobile &
Where a background task run                                                          Development


                                                           TimeTrigger
                                                          SystemTrigger
               ControlChannelTrigger                    MaintenanceTrigger


                     Application                         BackgroundTaskHost.exe




                                        Application or
                                   BackgroundTaskHost.exe



                               PushNotificationTrigger




@   itcampro    # itcamp12            Premium conference on Microsoft technologies
Mobile &
Notifications                                                              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
Mobile &
Basic steps to implement                                                     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
Mobile &
Base classes                                                               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
Mobile &
Live demo                                                                  Development




@   itcampro   # itcamp12   Premium conference on Microsoft technologies
Mobile &
CPU resource constrains                                                          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
Mobile &
Network resource constraints                                                               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
Mobile &
Tips and tricks                                                            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
Mobile &
Best practices                                                             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
@   itcampro   # itcamp12   Premium conference on Microsoft technologies
THE END



                                                           Radu Vunvulea
                                                                  iQuest
                                       http://vunvulearadu.blogspot.com
                                                 Twitter: @RaduVunvulea

@   itcampro   # itcamp12    Premium conference on Microsoft technologies

More Related Content

PDF
ITCamp 2012 - Radu Vunvulea - Building metro style applications on Windows 8 ...
PPSX
MBM's InterGuard Security Suite
PDF
ITCamp 2012 - Martin Kulov - Using the cloud for load testing
PDF
Lotus Notes Mobile Application Development Using XPages
PPTX
Smart, Data-Centric Security for the Post-PC Era
PPTX
The changing computer for small biz
PDF
Meego의 현재와 미래(2)
PDF
Trend Micro - Virtualization and Security Compliance
ITCamp 2012 - Radu Vunvulea - Building metro style applications on Windows 8 ...
MBM's InterGuard Security Suite
ITCamp 2012 - Martin Kulov - Using the cloud for load testing
Lotus Notes Mobile Application Development Using XPages
Smart, Data-Centric Security for the Post-PC Era
The changing computer for small biz
Meego의 현재와 미래(2)
Trend Micro - Virtualization and Security Compliance

What's hot (20)

PDF
Introduction - Trend Micro Deep Security
PDF
Security Technology Arms Race - Hack in the Box 2021 keynote
PDF
Trend Micro Dec 6 Toronto VMUG
PDF
Developing for Windows Phone 8.1 (Dan Ardelean)
PPTX
Developing for Windows Phone 8.1
PDF
IPNexus Datasheet
PPTX
Trend Micro - 13martie2012
PDF
Mikehall FutureWorld 2010 - enabling connectivity
PPT
Barco CineCare Web
PDF
Empower Employee to Work Anyplace, Amytime
PDF
Android Internals
PPTX
Mobilemonday b2b mobco
PDF
Moderne device management door middel van cloud
PPTX
BYOD - Protecting Your School
PDF
Tech trendnotes
DOCX
Mobile application development
PDF
Cloud Security: Perception Vs. Reality
PPT
Trend micro - Your journey to the cloud, where are you
PDF
Mitigating Risk for the Mobile Worker: Novell ZENworks Endpoint Security Mana...
PDF
실전 윈도우폰 망고 앱 디자인 & 개발 III(최종)
Introduction - Trend Micro Deep Security
Security Technology Arms Race - Hack in the Box 2021 keynote
Trend Micro Dec 6 Toronto VMUG
Developing for Windows Phone 8.1 (Dan Ardelean)
Developing for Windows Phone 8.1
IPNexus Datasheet
Trend Micro - 13martie2012
Mikehall FutureWorld 2010 - enabling connectivity
Barco CineCare Web
Empower Employee to Work Anyplace, Amytime
Android Internals
Mobilemonday b2b mobco
Moderne device management door middel van cloud
BYOD - Protecting Your School
Tech trendnotes
Mobile application development
Cloud Security: Perception Vs. Reality
Trend micro - Your journey to the cloud, where are you
Mitigating Risk for the Mobile Worker: Novell ZENworks Endpoint Security Mana...
실전 윈도우폰 망고 앱 디자인 & 개발 III(최종)
Ad

Viewers also liked (15)

PPTX
How to migrate a monolithic system to microservices, Radu Vunvulea DevTalks, ...
PPTX
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
PPTX
First 13 steps to be able to design an application for Azure Service Fabric
PPTX
How to use windows azure features on windows
PPTX
Radu vunvulea refactoring&code smells
PPTX
HDFS and Hadoop
PPTX
Backbone.js - Dragos Andronic
PPTX
Radu vunvulea building and testing windows 8 metro style applications using ...
PPTX
How to crunch 1 m messages per second in 4 easy steps - Radu Vunvulea
PPTX
Load tests using visual studio 2013 and Cloud
PPTX
Mobile services on windows azure (part2)
PPTX
The Real Life Story of an Iot framework,ITDevConnect 2016, Bucharest, Radu Vu...
PPTX
Good design of a startup product
PPTX
What about Azure IoT Hub | Radu Vunvulea
PPTX
Docker + .NET Core Demos | Radu Vunvulea
How to migrate a monolithic system to microservices, Radu Vunvulea DevTalks, ...
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
First 13 steps to be able to design an application for Azure Service Fabric
How to use windows azure features on windows
Radu vunvulea refactoring&code smells
HDFS and Hadoop
Backbone.js - Dragos Andronic
Radu vunvulea building and testing windows 8 metro style applications using ...
How to crunch 1 m messages per second in 4 easy steps - Radu Vunvulea
Load tests using visual studio 2013 and Cloud
Mobile services on windows azure (part2)
The Real Life Story of an Iot framework,ITDevConnect 2016, Bucharest, Radu Vu...
Good design of a startup product
What about Azure IoT Hub | Radu Vunvulea
Docker + .NET Core Demos | Radu Vunvulea
Ad

Similar to Vunvulea radu it camp-ro 2012 - building metro style applications on windows 8 using background tasks (20)

PDF
ITCamp 2011 - Adrian Stoian - System Center Configuration Manager 2012
PDF
ITCamp 2012 - Paula Januszkiewicz - Stronghold to Strengthen
PDF
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
PDF
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
PDF
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
PDF
ITCamp 2011 - Mihai Nadas - Windows Azure interop
PDF
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
PDF
ITCamp 2012 - Ovidiu Stan - Social media platform with Telligent Community, W...
PDF
ITCamp 2011 - Paula Januszkiewicz - 10 deadly sins of Windows Administrators
PDF
ITCamp 2013 - Petru Jucovschi - Application ecosystems
PPTX
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
PDF
NXP'S-PORTFOLIO-FOR-ADDRESSING-IOT-SECURITY.pdf
PDF
ITCamp 2012 - Dan Fizesan - Serving 10 million requests per day
PDF
ITCamp 2012 - Mihai Nadas - Tackling the single sign-on challenge
PDF
How to Tackle the Single Sign-On Challenge in 2012
PDF
ITCamp 2013 - Melania Danciu - HTML5 apps with LightSwitch
PDF
ITCamp 2011 - Melania Danciu - Mobile apps
PDF
ITCamp 2012 - Adam Granicz - Web development with WebSharper in F#
PDF
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
PDF
ITCamp 2012 - Florin Cardasim - HTML5 web-sockets
ITCamp 2011 - Adrian Stoian - System Center Configuration Manager 2012
ITCamp 2012 - Paula Januszkiewicz - Stronghold to Strengthen
Elements of DDD with ASP.NET MVC & Entity Framework Code First v2
Mihai Tataran - Building Windows 8 Applications with HTML5 and JS
ITCamp 2013 - Lorant Domokos - Chasing the one codebase, multiple platforms d...
ITCamp 2011 - Mihai Nadas - Windows Azure interop
ITCamp 2013 - Raffaele Rialdi - Windows Runtime (WinRT) deep dive
ITCamp 2012 - Ovidiu Stan - Social media platform with Telligent Community, W...
ITCamp 2011 - Paula Januszkiewicz - 10 deadly sins of Windows Administrators
ITCamp 2013 - Petru Jucovschi - Application ecosystems
ItCamp2012-Real-Time-Web-Web-Sockets-Windows 8- Florin-Cardasim
NXP'S-PORTFOLIO-FOR-ADDRESSING-IOT-SECURITY.pdf
ITCamp 2012 - Dan Fizesan - Serving 10 million requests per day
ITCamp 2012 - Mihai Nadas - Tackling the single sign-on challenge
How to Tackle the Single Sign-On Challenge in 2012
ITCamp 2013 - Melania Danciu - HTML5 apps with LightSwitch
ITCamp 2011 - Melania Danciu - Mobile apps
ITCamp 2012 - Adam Granicz - Web development with WebSharper in F#
ITCamp 2013 - Martin Kulov - Demystifying Visual Studio 2012 Performance Tools
ITCamp 2012 - Florin Cardasim - HTML5 web-sockets

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MIND Revenue Release Quarter 2 2025 Press Release
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

Vunvulea radu it camp-ro 2012 - building metro style applications on windows 8 using background tasks

  • 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. Mobile & ITCamp 2012 sponsors Development @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 3. Mobile & Agenda 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. Mobile & Why we need background tasks Development • What happens with classic applications? • Where Windows Services vanish? • Why do I need background tasks? @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 5. Mobile & Why we need background tasks Development • What happens with classic applications? • Where Windows Services vanish? • Why do I need background tasks? @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 6. Mobile & Windows Metro Applications Development • Similar to Windows Phone applications • Only threads from the current application (foreground) are running @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 7. Mobile & Background tasks 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. Mobile & Background task types 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. Mobile & When to use them 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. Mobile & Background task triggers Development ControlChannelTrigger ServicingComplete InternetAvailable SessionConnected InternetNotAvailable SessionDisconnected LockScreenApplicationAdded SessionStart LockScreenApplicationRemoved SmsReceived MaintenanceTrigger TimeTrigger NetworkNotificationChannelReset TimeZoneChange NetworkStateChange UserAway OnlineIdConnectedStateChange UserPresent PushNotificationTrigger @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 11. Mobile & Background task triggers Development ControlChannelTrigger ServicingComplete InternetAvailable SessionConnected InternetNotAvailable SessionDisconnected LockScreenApplicationAdded SessionStart LockScreenApplicationRemoved SmsReceived MaintenanceTrigger TimeTrigger NetworkNotificationChannelReset TimeZoneChange NetworkStateChange UserAway OnlineIdConnectedStateChange UserPresent PushNotificationTrigger @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 12. Mobile & Background task triggers Development • Some triggers require the application to be on the lock screen ControlChannelTrigger ServicingComplete InternetAvailable SessionConnected InternetNotAvailable SessionDisconnected LockScreenApplicationAdded SessionStart LockScreenApplicationRemoved SmsReceived MaintenanceTrigger TimeTrigger NetworkNotificationChannelReset TimeZoneChange NetworkStateChange UserAway OnlineIdConnectedStateChange UserPresent PushNotificationTrigger • An application can register to be notified when it is added or removed from lock screen @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 13. Mobile & Background task conditions 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. Mobile & Background task infrastructure 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. Mobile & Where a background task run Development Application BackgroundTaskHost.exe Application or BackgroundTaskHost.exe @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 16. Mobile & Where a background task run Development TimeTrigger SystemTrigger ControlChannelTrigger MaintenanceTrigger Application BackgroundTaskHost.exe Application or BackgroundTaskHost.exe PushNotificationTrigger @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 17. Mobile & Notifications 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. Mobile & Basic steps to implement 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. Mobile & Base classes 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. Mobile & Live demo Development @ itcampro # itcamp12 Premium conference on Microsoft technologies
  • 21. Mobile & CPU resource constrains 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. Mobile & Network resource constraints 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. Mobile & Tips and tricks 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. Mobile & Best practices 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