SlideShare a Scribd company logo
1 of 82
A look behind the scenes:
Windows 8 background
processing
Gill Cleeren
@gillcleeren
About me…
• Gill Cleeren
• .NET Architect @Ordina
• Pluralsight trainer
• Microsoft Regional Director
• Client Dev MVP
• Speaker
• User group lead (www.visug.be)
• Author
• Blog: www.snowball.be
• Email: gill@snowball.be
• Twitter: @gillcleeren
See my courses on Pluralsight!
• See my courses at
http://gicl.me/PluralsightCourses
Agenda
• Windows 8 lifecycle explained
• Background processing options
• Server-side
• Background tasks
• Lock screen apps
• Alarm apps (new in Windows 8.1)
• Geofencing (new in Windows 8.1)
• Background transfers
• Background audio
Q: Why do we need background
APIs?
A: The process lifecycle of Windows 8
Before Windows 8…
User was in control
Now, since Windows 8…
Windows 8 handles the process
lifecycle itself
• No dialogs
• Give the user the best experience
• App should give the impression it has
been running all the time
Typical aspects of the process lifecycle
1 app in the
foreground
System of app
events exists
User must be
unaware
Background
processing exists
The process lifecycle
Not running
Running
Suspended
Not running/
Terminated
Launching Suspending
Resuming
Termination
App Close
App crash
Demo
The Application-Circle-of-Life
It’s an event thing…
• Launched
• Happens when user taps tile
• PreviousExecutionState indicates if the app was
• Activation
• Most often in combination with a contract
• Search
• Share
• Doesn’t trigger the Launched event handler code!
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{ ... }
It’s an event thing…
• Suspending
• Last chance to save state
• Apps won’t get suspended in critical code blocks
• 5 seconds before suspending fires
• 5 seconds to execute code
• Resuming
• Can only happen is app is suspended, not terminated
• Same memory instance
• Immediate
• Typical use: data-rehydration
App, you are… terminated!
• Termination
• Not an event that we see in code
• Triggered by Windows
• Low memory resources
• Application closed by user
• App crash
• User logoff
State management
• Application events can be used to manage state
• User must think that app has been running all the time
• Options:
• SuspensionManager
• Available already in Windows 8
• In Windows 8.1, integrated in NavigationHelper
• Application Data API
• Local
• Roaming
• Service
• Time issues possible
Demo
Application events
Q: OK, what background
processing options do we have?
A: Quite a few actually! Let’s take a look!
Options for background processing
Server-side • Push notifications
Client-side
• Background tasks
• Lock screen apps
• Alarm apps
• Geofencing
• Background transfer
• Background audio
Push notifications
Server-side
Push notifications
• WNS = Windows Notification Service
• Allows delivery of tile and toast XML messages over the wire
• Can arrive when the app isn’t running
• Create background processing without processing
• Happens on the server
• Transparent process for the developer
• Free services
• Cloud-based so no worries on scalability
• Easily updates millions of devices
• Register your app in the store
• No need to publish!
• You can use Azure for every component
• It’s recommended to do so even!
Push notification architecture
1. Request Channel URI
2. Register with your Cloud Service
3. Authenticate & Push Notification
Demo
Push notifications
Background tasks
Client-side
Background tasks in general
• Balance between UX and hardware restrictions
• Battery, network…
• Windows 8 locks down what apps can do in the background
• An app can’t keep running when it’s not in the foreground
• Only “small amounts of code” are possible
• Constrained environment  hard for some scenarios
• Typical uses
• Download data from a service
• Send notification to the user
• …
• Run all the time
• Once registered, run when app is running and when it’s not running
Building blocks of a background task
BackgroundTaskBuilder
MyBackgroundTask
IBackgroundTask
Trigger
Condition
TaskEntryPoint: MyBackgroundTask
Your background code
• A class which implements IBackgroundTask
public sealed class MyBackgroundTask: IBackgroundTask
{
public void Run(IBackgroundTaskInstance task)
{
// Insert background code
}
}
Triggers
• Background task only starts when a trigger is firing
• One task, one trigger
• Trigger is an “event” that happens in the system
New background events in Windows 8.1
• BackgroundWorkCostChanged
• Related to Background Work Costs
• Based on what is scheduled, we can decide not to run our background task
• This event allows you to change your background API strategy based on
what's currently going on with the system
• NfcStateChange
• Allows your app to respond to near field communication (NFC) events for your
device even when the app isn't currently active
27
New background triggers in Windows 8.1
• DeviceUseTrigger
• Represents an event that an application can trigger to initiate a fixed-length,
long-running operation (content transfer, sync) with a device
• DeviceServicingTrigger
• Represents an event that an application can trigger to initiate a long-running
update (firmware or settings) of a device
• … LocationTrigger (later)
28
Conditions
• Can be added on trigger
• Trigger only fires when condition is true
• Can help not to waste valuable resources
Preparing your solution
• Registering a background task is done using Package manifest
Preparing your solution
One last thing before I’m deferred…
• If you have async code in the Run() of IBackgroundTask, you’ll need a
deferral
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
// be awesome asynchronally
deferral.Complete();
}
Constraints
• Background tasks are limited in the usage of
• CPU
- Network
- Not constrained when running on AC power
- Modeled as the amount of energy the network is used to transfer bytes
- Not based on throughput
• Critical tasks receive guaranteed application resource quotas
CPU resource quota Refresh period
Lock screen app 2 CPU seconds 15 minutes
Non-lock screen app 1 CPU second 2 hours
Demo:
Working in the background
Tomorrow in the office…
Debugging background tasks is time
consuming, boss. I have to toggle my
internet connection every time.
What? Didn’t you attend the user group
talk on background tasks in WinRT??
Can’t say I did…
(leaves the room quietly…)
Debugging background tasks
Make sure the
names match!
Manually trigger from Visual Studio
Demo:
Working Debugging in the background
The
screen
The lock screen and lock screen apps
• A set of APIs only available when the user puts the app on the lock
screen
• WNS (Push Notifications): RAW notification that can trigger code execution
• Network Trigger: constant connection
• Time trigger: execute code at specific intervals
• Less constraints
• Apps can become a lock screen only by using these triggers
• Not every app should be on the lock screen!
• An app can only ask once
• User can enable/disable it through Permissions settings pane
The lock screen and lock screen apps
• Only 7 apps can be on the lock screen
• User-managed
• App should be able to function if not on the lock screen too
• When on the lock screen:
• Can update the badge
• Display tile if promoted
• Display toast that opens the app after login
Demo:
Take a loOk at the loCk screen
Creating a lock screen app
• Step 1: Include a background task that requires lock screen
permission
Creating a lock screen app
• Step 2: add required logos (manifest)
• Lock screen badge logo
• Wide logo for the app
• Step 3: enable lock screen notifications in manifest
Demo:
Creating a lock screen app
Available triggers for lock screen apps
Push notification trigger
Control channel trigger
Time trigger
Push notification trigger
• WNS: allows sending push updates
• Templated XML only
• Push Notification Trigger enables triggering a background task AND
receiving just any string
• RAW notification
• 5K max
• All apps use same open connection
• Efficient
• No extra open sockets
• App can still update lock screen or trigger code
• Delivered on best-effort basis
Steps to enable the Push Notification trigger
• On the client
• Channel URI
• Background task
• Push Notification trigger
• On the server
• Authenticate
• Send any string to client (raw notification)
PushNotificationTrigger pushNotificationTrigger =
new PushNotificationTrigger();
When would you use this?
• Notify the client that action is required
Demo:
Raw notifications
Network trigger
• If server-side can’t use WNS, we need to fall back on sockets
• Open connection in the background
• Complex to create
• Not good for battery
• Guaranteed delivery
Network trigger
• 2 types exist
• Control channel trigger
• Required
• Persistent connection between client and server
• Initiated by the client
• Maintained by Windows even when the app is in the background
• Keep-alive trigger
• Optional
• Client can send keep-alive messages even when in background
Time trigger
• Can run code based on time interval
• Minimum is 15 minutes
• Requires app to be on the lock screen
• Code ignored if not
• Requires manifest change to use Timer
• Useful for POP3 mail checks, perform a service call
Demo
Time trigger
Windows 8 and alarms
• In Windows 8, it’s not possible to build an alarm app…
• Background process?
• Lock screen?
• Time trigger?
Windows 8.1 now has the Alarms App
• Can be an alarm clock, timer and stopwatch
So, there’s a way now!
• Windows 8.1 adds the ability to make an app the Alarm app
• Can show toasts (including sound) at specific time
• Precise to the second
• When the app is the alarm app, it can show special toast messages
Steps to Become an Alarm App
• Make the app lock-screen enabled
• Select the Timer, Control channel
or Push Notification
• Make the app Toast capable
• Define a badge logo
Steps to Become an Alarm App
• Edit the manifest XML
• No option to do this from the manifest designer
59
<Extensions>
<Extension Category="windows.backgroundTasks"
EntryPoint="App">
<BackgroundTasks>
<Task Type="timer" />
</BackgroundTasks>
</Extension>
<m2:Extension Category="windows.alarm" />
</Extensions>
Steps to Become an Alarm App
• Request alarm access from the app
• Use the AlarmApplicationManager.RequestAccessAsync()
• Create the scheduled toast notification
• Set Duration to Long
• Add custom commands (snooze and dismiss)
• Specify the snooze interval
Demo: ALAAAARM!!!
Geofencing
Coffee
house
Works with GPS, Wi-Fi
or IP address
Usages for geofencing
• “Remember the milk!”
• Let the user know about delays at his (train)station
• Check in on FourSquare automatically
• Coupon-codes for stores
• Virtual tour guide
• …
Steps to Enable Geofencing in Your App
• App must have required permissions
• In the manifest, app must have a Location task
• Containing a background task is therefore required
• Must have lock-screen permissions
• Can prompt the user, only once though
• Afterwards, still possible from Settings
• Setting up the geofence
• Only circular fences are supported
• Contains latitude, longitude and radius
• Get in notifications when entering or leaving the geofence
Demo:
Geofencing
BackgroundTransfer API
• Allows uploading and downloading (large) files from outside the app
• Runs when app is suspended
• Download is performed in a separate process
• BackgroundTransferHost.exe
• Lives in Windows.Networking.BackgroundTransfer namespace
• BackgroundDownloader & BackgroundUploader
Protocol Upload Download
HTTP
X X
HTTPS
X X
FTP
X
BackgroundTransfer API
• Handles network status changes and glitches
• Auto recovery
• Other supported features
Flow to transfer files
Start
Pause
ResumeStartAsync()
Transferring a file
private async void DownloadFile(Uri source, StorageFile destinationFile)
{
var downloader = new BackgroundDownloader();
var dl = downloader.CreateDownload(source,
destinationFile);
await dl.StartAsync();
}
Background Transfer Updates
• BackgroundTransferGroup allows apps to group transfer and change
their priority
• Do downloads in parallel or serial
• Possible to use a tile or toast update with the status of the transfer
• BackgroundDownloader and BackgroundUploader have been extended
• FailureTileNotification
• FailureToastNotification
• SuccessToastNotification
• SuccessTileNotification
Demo:
Transferring files
Playing audio in the background
• Audio can be played using the MediaElement
• Pauses the playback when app is suspended
• MediaElement defines AudioCategory property
• 2 options exist to enable
background audio public enum AudioCategory
{
Other = 0,
ForegroundOnlyMedia = 1,
BackgroundCapableMedia = 2,
Communications = 3,
Alerts = 4,
SoundEffects = 5,
GameEffects = 6,
GameMedia = 7,
}
Register from transport controls
Register for transport controls
• In Windows 8:
• Register for MediaControl events
• PlayPauseTogglePressed
• PlayPressed
• PausePressed
• StopPressed
• (optional) SoundLevelChanged
• Option will probably be discontinued after Windows 8.1
Register for transport controls
• In Windows 8.1
• Use the SystemMediaTransportControls
• Not a static class that exposes events
• Can be accessed through the GetForCurrentView static method
• All events are processed through the single ButtonPressed event
• Offers more options
• Record, rewind…
Demo:
Playing music in the background
Summary
• Background processing in Windows 8 is limited and constrained
• Different approach than in previous editions
• Background tasks and lock screen apps allow to run small blocks of
code
• Downloading in the background and playing audio is supported
More info?
• Check out my Pluralsight course on this topic
http://gicl.me/PSWin8BGProc
Q&A
Thanks!
A look behind the scenes:
Windows 8 background
processing
Gill Cleeren
@gillcleeren

More Related Content

What's hot

CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: DebuggingSam Bowne
 
Gdco12 kartik ayyar
Gdco12 kartik ayyarGdco12 kartik ayyar
Gdco12 kartik ayyarKartik Ayyar
 
Expedia 3x3 presentation
Expedia 3x3 presentationExpedia 3x3 presentation
Expedia 3x3 presentationDrew Hannay
 
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deployments
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deploymentsJohan Arwidmark - Troubleshooting SCCM 2012 R2 OS deployments
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deploymentsNordic Infrastructure Conference
 
SynapseIndia drupal presentation on drupal info
SynapseIndia drupal  presentation on drupal infoSynapseIndia drupal  presentation on drupal info
SynapseIndia drupal presentation on drupal infoSynapseindiappsdevelopment
 
In the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notificationsIn the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notificationsJan Haložan
 
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...Nordic Infrastructure Conference
 
Integration Testing as Validation and Monitoring
 Integration Testing as Validation and Monitoring Integration Testing as Validation and Monitoring
Integration Testing as Validation and MonitoringMelissa Benua
 
ELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot TimesELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot Timesandrewmurraympc
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupViktor Gamov
 
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisCNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisSam Bowne
 
Enterprise PowerShell for Remote Security Assessments
Enterprise PowerShell for Remote Security AssessmentsEnterprise PowerShell for Remote Security Assessments
Enterprise PowerShell for Remote Security AssessmentsEnclaveSecurity
 
Leveraging HP Performance Center
Leveraging HP Performance CenterLeveraging HP Performance Center
Leveraging HP Performance CenterMartin Spier
 
DEF CON 23 - Rickey Lawshae - lets talk about soap
DEF CON 23 - Rickey Lawshae - lets talk about soapDEF CON 23 - Rickey Lawshae - lets talk about soap
DEF CON 23 - Rickey Lawshae - lets talk about soapFelipe Prado
 
CNIT 152: 6. Scope & 7. Live Data Collection
CNIT 152: 6. Scope & 7. Live Data CollectionCNIT 152: 6. Scope & 7. Live Data Collection
CNIT 152: 6. Scope & 7. Live Data CollectionSam Bowne
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecuritySam Bowne
 
Application Virtualization, University of New Hampshire
Application Virtualization, University of New HampshireApplication Virtualization, University of New Hampshire
Application Virtualization, University of New HampshireTony Austwick
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsInductive Automation
 
TI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBootTI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBootandrewmurraympc
 

What's hot (20)

CNIT 126 8: Debugging
CNIT 126 8: DebuggingCNIT 126 8: Debugging
CNIT 126 8: Debugging
 
Gdco12 kartik ayyar
Gdco12 kartik ayyarGdco12 kartik ayyar
Gdco12 kartik ayyar
 
Expedia 3x3 presentation
Expedia 3x3 presentationExpedia 3x3 presentation
Expedia 3x3 presentation
 
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deployments
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deploymentsJohan Arwidmark - Troubleshooting SCCM 2012 R2 OS deployments
Johan Arwidmark - Troubleshooting SCCM 2012 R2 OS deployments
 
SynapseIndia drupal presentation on drupal info
SynapseIndia drupal  presentation on drupal infoSynapseIndia drupal  presentation on drupal info
SynapseIndia drupal presentation on drupal info
 
In the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notificationsIn the hunt of 100% delivery rate with mobile push notifications
In the hunt of 100% delivery rate with mobile push notifications
 
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...
Kent Agerlund - Via monstra part 4 become the hero of the day, master configm...
 
TestIstanbul 2015
TestIstanbul 2015TestIstanbul 2015
TestIstanbul 2015
 
Integration Testing as Validation and Monitoring
 Integration Testing as Validation and Monitoring Integration Testing as Validation and Monitoring
Integration Testing as Validation and Monitoring
 
ELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot TimesELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot Times
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user group
 
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic AnalysisCNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
CNIT 126 2: Malware Analysis in Virtual Machines & 3: Basic Dynamic Analysis
 
Enterprise PowerShell for Remote Security Assessments
Enterprise PowerShell for Remote Security AssessmentsEnterprise PowerShell for Remote Security Assessments
Enterprise PowerShell for Remote Security Assessments
 
Leveraging HP Performance Center
Leveraging HP Performance CenterLeveraging HP Performance Center
Leveraging HP Performance Center
 
DEF CON 23 - Rickey Lawshae - lets talk about soap
DEF CON 23 - Rickey Lawshae - lets talk about soapDEF CON 23 - Rickey Lawshae - lets talk about soap
DEF CON 23 - Rickey Lawshae - lets talk about soap
 
CNIT 152: 6. Scope & 7. Live Data Collection
CNIT 152: 6. Scope & 7. Live Data CollectionCNIT 152: 6. Scope & 7. Live Data Collection
CNIT 152: 6. Scope & 7. Live Data Collection
 
CISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development SecurityCISSP Prep: Ch 9. Software Development Security
CISSP Prep: Ch 9. Software Development Security
 
Application Virtualization, University of New Hampshire
Application Virtualization, University of New HampshireApplication Virtualization, University of New Hampshire
Application Virtualization, University of New Hampshire
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise Solutions
 
TI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBootTI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBoot
 

Viewers also liked

Pricing mobile apps
Pricing mobile appsPricing mobile apps
Pricing mobile appsMatt Lacey
 
Wpug vserv developer deck- march 2014 global
Wpug  vserv developer deck- march 2014 globalWpug  vserv developer deck- march 2014 global
Wpug vserv developer deck- march 2014 globalMatt Lacey
 
Intro to the App Developers Alliance @ WPUG
Intro to the App Developers Alliance @ WPUGIntro to the App Developers Alliance @ WPUG
Intro to the App Developers Alliance @ WPUGMatt Lacey
 
Is your mobile app as secure as you think?
Is your mobile app as secure as you think?Is your mobile app as secure as you think?
Is your mobile app as secure as you think?Matt Lacey
 
"Write Once, Run Everywhere" & Windows 10
"Write Once, Run Everywhere" & Windows 10"Write Once, Run Everywhere" & Windows 10
"Write Once, Run Everywhere" & Windows 10Matt Lacey
 

Viewers also liked (6)

Pricing mobile apps
Pricing mobile appsPricing mobile apps
Pricing mobile apps
 
Wpug vserv developer deck- march 2014 global
Wpug  vserv developer deck- march 2014 globalWpug  vserv developer deck- march 2014 global
Wpug vserv developer deck- march 2014 global
 
Intro to the App Developers Alliance @ WPUG
Intro to the App Developers Alliance @ WPUGIntro to the App Developers Alliance @ WPUG
Intro to the App Developers Alliance @ WPUG
 
Is your mobile app as secure as you think?
Is your mobile app as secure as you think?Is your mobile app as secure as you think?
Is your mobile app as secure as you think?
 
"Write Once, Run Everywhere" & Windows 10
"Write Once, Run Everywhere" & Windows 10"Write Once, Run Everywhere" & Windows 10
"Write Once, Run Everywhere" & Windows 10
 
Sustainability
SustainabilitySustainability
Sustainability
 

Similar to A look behind the scenes: Windows 8 background processing

PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux Neotys
 
Windows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsWindows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsOliver Scheer
 
OpenNTF Webinar - October 2021: Return of the DOTS
OpenNTF Webinar - October 2021: Return of the DOTSOpenNTF Webinar - October 2021: Return of the DOTS
OpenNTF Webinar - October 2021: Return of the DOTSSerdar Basegmez
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxNgLQun
 
Creating Havoc using Human Interface Device
Creating Havoc using Human Interface DeviceCreating Havoc using Human Interface Device
Creating Havoc using Human Interface DevicePositive Hack Days
 
Windows 8 DevUnleashed - Session 3
Windows 8 DevUnleashed - Session 3Windows 8 DevUnleashed - Session 3
Windows 8 DevUnleashed - Session 3drudolph11
 
Microservices: The Best Practices
Microservices: The Best PracticesMicroservices: The Best Practices
Microservices: The Best PracticesPavel Mička
 
Panther Sniffer for DQMH®.pptx
Panther Sniffer for DQMH®.pptxPanther Sniffer for DQMH®.pptx
Panther Sniffer for DQMH®.pptxEnriqueNo2
 
Sinergija 11 WP7 Mango multitasking and “multitasking”
Sinergija 11   WP7 Mango multitasking and “multitasking”Sinergija 11   WP7 Mango multitasking and “multitasking”
Sinergija 11 WP7 Mango multitasking and “multitasking”Catalin Gheorghiu
 
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)PROIDEA
 
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...NCCOMMS
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyserAlex Moskvin
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon chinaPeter Hlavaty
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsInductive Automation
 
08.Push Notifications
08.Push Notifications 08.Push Notifications
08.Push Notifications Nguyen Tuan
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1drudolph11
 
An Introduction to the Model-View-Controller Pattern
An Introduction to the Model-View-Controller PatternAn Introduction to the Model-View-Controller Pattern
An Introduction to the Model-View-Controller PatternTeamstudio
 

Similar to A look behind the scenes: Windows 8 background processing (20)

PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux
 
Windows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background AgentsWindows Phone 8 - 6 Background Agents
Windows Phone 8 - 6 Background Agents
 
OpenNTF Webinar - October 2021: Return of the DOTS
OpenNTF Webinar - October 2021: Return of the DOTSOpenNTF Webinar - October 2021: Return of the DOTS
OpenNTF Webinar - October 2021: Return of the DOTS
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 
How we use Twisted in Launchpad
How we use Twisted in LaunchpadHow we use Twisted in Launchpad
How we use Twisted in Launchpad
 
Creating Havoc using Human Interface Device
Creating Havoc using Human Interface DeviceCreating Havoc using Human Interface Device
Creating Havoc using Human Interface Device
 
Android OS
Android OSAndroid OS
Android OS
 
Windows 8 DevUnleashed - Session 3
Windows 8 DevUnleashed - Session 3Windows 8 DevUnleashed - Session 3
Windows 8 DevUnleashed - Session 3
 
Microservices: The Best Practices
Microservices: The Best PracticesMicroservices: The Best Practices
Microservices: The Best Practices
 
Panther Sniffer for DQMH®.pptx
Panther Sniffer for DQMH®.pptxPanther Sniffer for DQMH®.pptx
Panther Sniffer for DQMH®.pptx
 
Sinergija 11 WP7 Mango multitasking and “multitasking”
Sinergija 11   WP7 Mango multitasking and “multitasking”Sinergija 11   WP7 Mango multitasking and “multitasking”
Sinergija 11 WP7 Mango multitasking and “multitasking”
 
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
4Developers 2018: Zero-Downtime deployments with Kubernetes (Mateusz Dymiński)
 
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Android overview
Android overviewAndroid overview
Android overview
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon china
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise Solutions
 
08.Push Notifications
08.Push Notifications 08.Push Notifications
08.Push Notifications
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1
 
An Introduction to the Model-View-Controller Pattern
An Introduction to the Model-View-Controller PatternAn Introduction to the Model-View-Controller Pattern
An Introduction to the Model-View-Controller Pattern
 

More from Matt Lacey

Modern XAML Development - Matt Lacey
Modern XAML Development - Matt LaceyModern XAML Development - Matt Lacey
Modern XAML Development - Matt LaceyMatt Lacey
 
10 tips for porting to Windows Phone 8
10 tips for porting to Windows Phone 810 tips for porting to Windows Phone 8
10 tips for porting to Windows Phone 8Matt Lacey
 
Preparing for WP8
Preparing for WP8Preparing for WP8
Preparing for WP8Matt Lacey
 
Thinking mobile and beyond (Dundee)
Thinking mobile and beyond (Dundee)Thinking mobile and beyond (Dundee)
Thinking mobile and beyond (Dundee)Matt Lacey
 
Awesome Windows Phone Development (Aberdeen)
Awesome Windows Phone Development (Aberdeen)Awesome Windows Phone Development (Aberdeen)
Awesome Windows Phone Development (Aberdeen)Matt Lacey
 
Deep linking and secondary tiles
Deep linking and secondary tilesDeep linking and secondary tiles
Deep linking and secondary tilesMatt Lacey
 
PhoneGap @ LDNUG
PhoneGap @ LDNUGPhoneGap @ LDNUG
PhoneGap @ LDNUGMatt Lacey
 
Introducing Windows Phone 7 Development
Introducing Windows Phone 7 DevelopmentIntroducing Windows Phone 7 Development
Introducing Windows Phone 7 DevelopmentMatt Lacey
 
WP7Dev with HTML & JavaScript
WP7Dev with HTML & JavaScriptWP7Dev with HTML & JavaScript
WP7Dev with HTML & JavaScriptMatt Lacey
 
Why care about mobile? And what is Windows Phone 7?
Why care about mobile? And what is Windows Phone 7?Why care about mobile? And what is Windows Phone 7?
Why care about mobile? And what is Windows Phone 7?Matt Lacey
 
Developing for Windows7 with the APICodepack
Developing for Windows7 with the APICodepackDeveloping for Windows7 with the APICodepack
Developing for Windows7 with the APICodepackMatt Lacey
 
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)Matt Lacey
 
Mobile Web 2.0 (DDD Scotland - Grok Talk)
Mobile Web 2.0 (DDD Scotland - Grok Talk)Mobile Web 2.0 (DDD Scotland - Grok Talk)
Mobile Web 2.0 (DDD Scotland - Grok Talk)Matt Lacey
 
Mobilise your ASP.NET website
Mobilise your ASP.NET websiteMobilise your ASP.NET website
Mobilise your ASP.NET websiteMatt Lacey
 
What you "really" need to know about developing for Windows Mobile
What you "really" need to know about developing for Windows MobileWhat you "really" need to know about developing for Windows Mobile
What you "really" need to know about developing for Windows MobileMatt Lacey
 

More from Matt Lacey (17)

Modern XAML Development - Matt Lacey
Modern XAML Development - Matt LaceyModern XAML Development - Matt Lacey
Modern XAML Development - Matt Lacey
 
10 tips for porting to Windows Phone 8
10 tips for porting to Windows Phone 810 tips for porting to Windows Phone 8
10 tips for porting to Windows Phone 8
 
Preparing for WP8
Preparing for WP8Preparing for WP8
Preparing for WP8
 
Thinking mobile and beyond (Dundee)
Thinking mobile and beyond (Dundee)Thinking mobile and beyond (Dundee)
Thinking mobile and beyond (Dundee)
 
Awesome Windows Phone Development (Aberdeen)
Awesome Windows Phone Development (Aberdeen)Awesome Windows Phone Development (Aberdeen)
Awesome Windows Phone Development (Aberdeen)
 
WPSDK 7.1.1
WPSDK 7.1.1WPSDK 7.1.1
WPSDK 7.1.1
 
Deep linking and secondary tiles
Deep linking and secondary tilesDeep linking and secondary tiles
Deep linking and secondary tiles
 
PhoneGap @ LDNUG
PhoneGap @ LDNUGPhoneGap @ LDNUG
PhoneGap @ LDNUG
 
Introducing Windows Phone 7 Development
Introducing Windows Phone 7 DevelopmentIntroducing Windows Phone 7 Development
Introducing Windows Phone 7 Development
 
WP7Dev with HTML & JavaScript
WP7Dev with HTML & JavaScriptWP7Dev with HTML & JavaScript
WP7Dev with HTML & JavaScript
 
Xna for wp7
Xna for wp7Xna for wp7
Xna for wp7
 
Why care about mobile? And what is Windows Phone 7?
Why care about mobile? And what is Windows Phone 7?Why care about mobile? And what is Windows Phone 7?
Why care about mobile? And what is Windows Phone 7?
 
Developing for Windows7 with the APICodepack
Developing for Windows7 with the APICodepackDeveloping for Windows7 with the APICodepack
Developing for Windows7 with the APICodepack
 
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)
Mobile Web 2.0 & MDBF (DDDSW - Grok Talk)
 
Mobile Web 2.0 (DDD Scotland - Grok Talk)
Mobile Web 2.0 (DDD Scotland - Grok Talk)Mobile Web 2.0 (DDD Scotland - Grok Talk)
Mobile Web 2.0 (DDD Scotland - Grok Talk)
 
Mobilise your ASP.NET website
Mobilise your ASP.NET websiteMobilise your ASP.NET website
Mobilise your ASP.NET website
 
What you "really" need to know about developing for Windows Mobile
What you "really" need to know about developing for Windows MobileWhat you "really" need to know about developing for Windows Mobile
What you "really" need to know about developing for Windows Mobile
 

Recently uploaded

Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...nishasame66
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesChandrakantDivate1
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsChandrakantDivate1
 
Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312wphillips114
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsChandrakantDivate1
 

Recently uploaded (6)

Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312Mobile App Penetration Testing Bsides312
Mobile App Penetration Testing Bsides312
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 

A look behind the scenes: Windows 8 background processing

  • 1. A look behind the scenes: Windows 8 background processing Gill Cleeren @gillcleeren
  • 2. About me… • Gill Cleeren • .NET Architect @Ordina • Pluralsight trainer • Microsoft Regional Director • Client Dev MVP • Speaker • User group lead (www.visug.be) • Author • Blog: www.snowball.be • Email: gill@snowball.be • Twitter: @gillcleeren
  • 3. See my courses on Pluralsight! • See my courses at http://gicl.me/PluralsightCourses
  • 4. Agenda • Windows 8 lifecycle explained • Background processing options • Server-side • Background tasks • Lock screen apps • Alarm apps (new in Windows 8.1) • Geofencing (new in Windows 8.1) • Background transfers • Background audio
  • 5. Q: Why do we need background APIs? A: The process lifecycle of Windows 8
  • 6. Before Windows 8… User was in control
  • 7. Now, since Windows 8… Windows 8 handles the process lifecycle itself • No dialogs • Give the user the best experience • App should give the impression it has been running all the time
  • 8. Typical aspects of the process lifecycle 1 app in the foreground System of app events exists User must be unaware Background processing exists
  • 9. The process lifecycle Not running Running Suspended Not running/ Terminated Launching Suspending Resuming Termination App Close App crash
  • 11. It’s an event thing… • Launched • Happens when user taps tile • PreviousExecutionState indicates if the app was • Activation • Most often in combination with a contract • Search • Share • Doesn’t trigger the Launched event handler code! protected override void OnLaunched(LaunchActivatedEventArgs args) { if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { ... }
  • 12. It’s an event thing… • Suspending • Last chance to save state • Apps won’t get suspended in critical code blocks • 5 seconds before suspending fires • 5 seconds to execute code • Resuming • Can only happen is app is suspended, not terminated • Same memory instance • Immediate • Typical use: data-rehydration
  • 13. App, you are… terminated! • Termination • Not an event that we see in code • Triggered by Windows • Low memory resources • Application closed by user • App crash • User logoff
  • 14. State management • Application events can be used to manage state • User must think that app has been running all the time • Options: • SuspensionManager • Available already in Windows 8 • In Windows 8.1, integrated in NavigationHelper • Application Data API • Local • Roaming • Service • Time issues possible
  • 16. Q: OK, what background processing options do we have? A: Quite a few actually! Let’s take a look!
  • 17. Options for background processing Server-side • Push notifications Client-side • Background tasks • Lock screen apps • Alarm apps • Geofencing • Background transfer • Background audio
  • 19. Push notifications • WNS = Windows Notification Service • Allows delivery of tile and toast XML messages over the wire • Can arrive when the app isn’t running • Create background processing without processing • Happens on the server • Transparent process for the developer • Free services • Cloud-based so no worries on scalability • Easily updates millions of devices • Register your app in the store • No need to publish! • You can use Azure for every component • It’s recommended to do so even!
  • 20. Push notification architecture 1. Request Channel URI 2. Register with your Cloud Service 3. Authenticate & Push Notification
  • 23. Background tasks in general • Balance between UX and hardware restrictions • Battery, network… • Windows 8 locks down what apps can do in the background • An app can’t keep running when it’s not in the foreground • Only “small amounts of code” are possible • Constrained environment  hard for some scenarios • Typical uses • Download data from a service • Send notification to the user • … • Run all the time • Once registered, run when app is running and when it’s not running
  • 24. Building blocks of a background task BackgroundTaskBuilder MyBackgroundTask IBackgroundTask Trigger Condition TaskEntryPoint: MyBackgroundTask
  • 25. Your background code • A class which implements IBackgroundTask public sealed class MyBackgroundTask: IBackgroundTask { public void Run(IBackgroundTaskInstance task) { // Insert background code } }
  • 26. Triggers • Background task only starts when a trigger is firing • One task, one trigger • Trigger is an “event” that happens in the system
  • 27. New background events in Windows 8.1 • BackgroundWorkCostChanged • Related to Background Work Costs • Based on what is scheduled, we can decide not to run our background task • This event allows you to change your background API strategy based on what's currently going on with the system • NfcStateChange • Allows your app to respond to near field communication (NFC) events for your device even when the app isn't currently active 27
  • 28. New background triggers in Windows 8.1 • DeviceUseTrigger • Represents an event that an application can trigger to initiate a fixed-length, long-running operation (content transfer, sync) with a device • DeviceServicingTrigger • Represents an event that an application can trigger to initiate a long-running update (firmware or settings) of a device • … LocationTrigger (later) 28
  • 29. Conditions • Can be added on trigger • Trigger only fires when condition is true • Can help not to waste valuable resources
  • 30. Preparing your solution • Registering a background task is done using Package manifest
  • 32. One last thing before I’m deferred… • If you have async code in the Run() of IBackgroundTask, you’ll need a deferral public void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); // be awesome asynchronally deferral.Complete(); }
  • 33. Constraints • Background tasks are limited in the usage of • CPU - Network - Not constrained when running on AC power - Modeled as the amount of energy the network is used to transfer bytes - Not based on throughput • Critical tasks receive guaranteed application resource quotas CPU resource quota Refresh period Lock screen app 2 CPU seconds 15 minutes Non-lock screen app 1 CPU second 2 hours
  • 34. Demo: Working in the background
  • 35. Tomorrow in the office… Debugging background tasks is time consuming, boss. I have to toggle my internet connection every time. What? Didn’t you attend the user group talk on background tasks in WinRT?? Can’t say I did… (leaves the room quietly…)
  • 36. Debugging background tasks Make sure the names match!
  • 37. Manually trigger from Visual Studio
  • 38. Demo: Working Debugging in the background
  • 40. The lock screen and lock screen apps • A set of APIs only available when the user puts the app on the lock screen • WNS (Push Notifications): RAW notification that can trigger code execution • Network Trigger: constant connection • Time trigger: execute code at specific intervals • Less constraints • Apps can become a lock screen only by using these triggers • Not every app should be on the lock screen! • An app can only ask once • User can enable/disable it through Permissions settings pane
  • 41. The lock screen and lock screen apps • Only 7 apps can be on the lock screen • User-managed • App should be able to function if not on the lock screen too • When on the lock screen: • Can update the badge • Display tile if promoted • Display toast that opens the app after login
  • 42. Demo: Take a loOk at the loCk screen
  • 43. Creating a lock screen app • Step 1: Include a background task that requires lock screen permission
  • 44. Creating a lock screen app • Step 2: add required logos (manifest) • Lock screen badge logo • Wide logo for the app • Step 3: enable lock screen notifications in manifest
  • 45. Demo: Creating a lock screen app
  • 46. Available triggers for lock screen apps Push notification trigger Control channel trigger Time trigger
  • 47. Push notification trigger • WNS: allows sending push updates • Templated XML only • Push Notification Trigger enables triggering a background task AND receiving just any string • RAW notification • 5K max • All apps use same open connection • Efficient • No extra open sockets • App can still update lock screen or trigger code • Delivered on best-effort basis
  • 48. Steps to enable the Push Notification trigger • On the client • Channel URI • Background task • Push Notification trigger • On the server • Authenticate • Send any string to client (raw notification) PushNotificationTrigger pushNotificationTrigger = new PushNotificationTrigger();
  • 49. When would you use this? • Notify the client that action is required
  • 51. Network trigger • If server-side can’t use WNS, we need to fall back on sockets • Open connection in the background • Complex to create • Not good for battery • Guaranteed delivery
  • 52. Network trigger • 2 types exist • Control channel trigger • Required • Persistent connection between client and server • Initiated by the client • Maintained by Windows even when the app is in the background • Keep-alive trigger • Optional • Client can send keep-alive messages even when in background
  • 53. Time trigger • Can run code based on time interval • Minimum is 15 minutes • Requires app to be on the lock screen • Code ignored if not • Requires manifest change to use Timer • Useful for POP3 mail checks, perform a service call
  • 55. Windows 8 and alarms • In Windows 8, it’s not possible to build an alarm app… • Background process? • Lock screen? • Time trigger?
  • 56. Windows 8.1 now has the Alarms App • Can be an alarm clock, timer and stopwatch
  • 57. So, there’s a way now! • Windows 8.1 adds the ability to make an app the Alarm app • Can show toasts (including sound) at specific time • Precise to the second • When the app is the alarm app, it can show special toast messages
  • 58. Steps to Become an Alarm App • Make the app lock-screen enabled • Select the Timer, Control channel or Push Notification • Make the app Toast capable • Define a badge logo
  • 59. Steps to Become an Alarm App • Edit the manifest XML • No option to do this from the manifest designer 59 <Extensions> <Extension Category="windows.backgroundTasks" EntryPoint="App"> <BackgroundTasks> <Task Type="timer" /> </BackgroundTasks> </Extension> <m2:Extension Category="windows.alarm" /> </Extensions>
  • 60. Steps to Become an Alarm App • Request alarm access from the app • Use the AlarmApplicationManager.RequestAccessAsync() • Create the scheduled toast notification • Set Duration to Long • Add custom commands (snooze and dismiss) • Specify the snooze interval
  • 63. Usages for geofencing • “Remember the milk!” • Let the user know about delays at his (train)station • Check in on FourSquare automatically • Coupon-codes for stores • Virtual tour guide • …
  • 64. Steps to Enable Geofencing in Your App • App must have required permissions • In the manifest, app must have a Location task • Containing a background task is therefore required • Must have lock-screen permissions • Can prompt the user, only once though • Afterwards, still possible from Settings • Setting up the geofence • Only circular fences are supported • Contains latitude, longitude and radius • Get in notifications when entering or leaving the geofence
  • 66. BackgroundTransfer API • Allows uploading and downloading (large) files from outside the app • Runs when app is suspended • Download is performed in a separate process • BackgroundTransferHost.exe • Lives in Windows.Networking.BackgroundTransfer namespace • BackgroundDownloader & BackgroundUploader Protocol Upload Download HTTP X X HTTPS X X FTP X
  • 67. BackgroundTransfer API • Handles network status changes and glitches • Auto recovery • Other supported features
  • 68. Flow to transfer files Start Pause ResumeStartAsync()
  • 69. Transferring a file private async void DownloadFile(Uri source, StorageFile destinationFile) { var downloader = new BackgroundDownloader(); var dl = downloader.CreateDownload(source, destinationFile); await dl.StartAsync(); }
  • 70. Background Transfer Updates • BackgroundTransferGroup allows apps to group transfer and change their priority • Do downloads in parallel or serial • Possible to use a tile or toast update with the status of the transfer • BackgroundDownloader and BackgroundUploader have been extended • FailureTileNotification • FailureToastNotification • SuccessToastNotification • SuccessTileNotification
  • 72. Playing audio in the background • Audio can be played using the MediaElement • Pauses the playback when app is suspended • MediaElement defines AudioCategory property • 2 options exist to enable background audio public enum AudioCategory { Other = 0, ForegroundOnlyMedia = 1, BackgroundCapableMedia = 2, Communications = 3, Alerts = 4, SoundEffects = 5, GameEffects = 6, GameMedia = 7, }
  • 73.
  • 75. Register for transport controls • In Windows 8: • Register for MediaControl events • PlayPauseTogglePressed • PlayPressed • PausePressed • StopPressed • (optional) SoundLevelChanged • Option will probably be discontinued after Windows 8.1
  • 76. Register for transport controls • In Windows 8.1 • Use the SystemMediaTransportControls • Not a static class that exposes events • Can be accessed through the GetForCurrentView static method • All events are processed through the single ButtonPressed event • Offers more options • Record, rewind…
  • 77. Demo: Playing music in the background
  • 78. Summary • Background processing in Windows 8 is limited and constrained • Different approach than in previous editions • Background tasks and lock screen apps allow to run small blocks of code • Downloading in the background and playing audio is supported
  • 79. More info? • Check out my Pluralsight course on this topic http://gicl.me/PSWin8BGProc
  • 80. Q&A
  • 82. A look behind the scenes: Windows 8 background processing Gill Cleeren @gillcleeren

Editor's Notes

  1. http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.background.deviceservicingtrigger.aspx http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.background.deviceusetrigger.aspx