SlideShare una empresa de Scribd logo
1 de 26
WP8 BACKGROUND AGENTS
1.

Windows Phone task management

2.

Multi-tasking with background agents

3.

Creating tasks in Visual Studio

4.

File transfer tasks

5.

Background notifications
FOLLOW US
Twitter

: @chothanihitesh

Slideshare

: http://www.slideshare.net/Chothani-Hitesh

Email

: chothani.hitesh@gmail.com

Support

: windows.chothani@live.com

LinkedIn

: in.linkedin.com/pub/hiteshchothani/6b/311/2b8

W8 Publisher

: AppStudios

WP Publisher : AppStudios
Website

: www.appmobinfotech.com
FOREGROUND TASKS


Normally a Windows Phone application runs in the “foreground”




Has access to screen and interacts directly with the user of the phone

At any given time one application is running in the foreground


Although others may be in the memory of the phone and can be selected as
required



This is to ensure the best possible performance and battery life for the
phone user
BACKGROUND AGENTS


A Windows Phone application can start a “background agent” to work
for it


It is a PeriodicTask, ResourceIntensiveTask or both at the same time



There is only one agent allowed per application



The agent can run when the main application is not in the foreground



An agent is not equivalent to a foreground application running in the
background


It is limited in what it can do and the access it has to the processor and other
phone facilities
BACKGROUND AGENT HEALTH WARNING


The number of agents allowed to be active at one time is restricted by
the Windows Phone operating system



If the right conditions do not arise for an agent it will not be started


Background agents only run in situations where the operating system feels able to
give them access to the processor



If the phone goes into “Power Saver” mode it may stop running
background agents completely



Users can also manage the agents running on their phone and may
chose to disable them
AGENTS AND TASKS


A Task is the scheduling type you request when you schedule a
background agent to run




It is managed by the operating system which runs the agent at the appointed time

There are two kinds of Tasks





Periodic tasks that are run every now and then
Resource intensive tasks that run when the phone is in a position to let them

The background Agent is the actual code functionality you write which
runs in the background and which does the work


The agent code is implemented in a class that derives from BackgroundAgent



The class is created as part of a Scheduled Task Agent Project
PERIODICTASK AGENTS


A PeriodicTask Agent runs every now and then




Typically every 30 minutes or so, depending on loading on the phone

It is intended to perform a task that should be performed regularly and
complete quickly



Memory usage allowed<= 6 MB



Unscheduled after two consecutive crashes





The agent is allowed to run for 25 seconds or so

The phone sets a limit on the maximum number of active agents at any time

Good for location tracking, polling background services, tile updates
RESOURCEINTENSIVE AGENTS


Resource Intensive Agents run when the phone is in a position where it
can usefully perform some data processing:



When the battery is >90% charged



When the phone is connected to WiFi





When the phone is powered by the mains

When the phone is not being used (Lock screen displayed)

A “resource intensive” agent can run for up to 10 minutes





Memory usage allowed<= 6 MB
Unscheduled after two consecutive crashes

Good for synchronisation with a host service, unpacking/preparing
resources, compressing databases
DUAL PURPOSE AGENTS


It is possible for an application to perform both periodic and resource
intensive work in the background



This can be achieved using a single background agent class, run from
both kinds of task



The agent will run periodically and when the phone is in a position to
allow resource intensive work



When the agent starts it can determine the context in which it is running
and then behave appropriately
BACKGROUND AGENT FUNCTIONALITY
LOCATION TRACKER


The Location Tracker program is a simple
logging application



It tracks the location of the phone by using
a background agent to regularly store the
location of the phone in a text log file



The agent will update the position even
when the log program is not active
CREATING A BACKGROUND AGENT


A background agent is
added to the
application solution as
a “Scheduled Task”



There is a Visual

Studio template just
for this


This agent will contain
the code that runs

when the agent is
active
THE CAPTAINS LOG SOLUTION FILE


The solution file contains two projects


LocationLogger: the Windows Phone project
which is the main application



LocationLogTaskAgent: the background agent
to perform the tracking



Solutions can contain many types of
different projects



When the solution is built all the assembly

file outputs will be combined and sent to
the phone
CONNECTING THE AGENT PROJECT


The CaptainsLog project contains a reference
to the output of the LocationTaskAgent
project



The foreground application does not directly

reference any objects in the agent class in
code


Nonetheless, we have to explicitly link these
two projects by adding a reference to the
LocationTaskAgent output to the
CaptainsLog project
BACKGROUND AGENT CODE



We must implement the agent functionality in the OnInvoke method



It notifies the run time system when it has completed
SHARING DATA WITH BACKGROUND
AGENTS



First thing agent does is load the log string from isolated storage



It is going to append the current location on the end of this string
CONCURRENT DATA ACCESS



Protect access to files in Isolated Storage by using a named Mutex



Make sure you release the mutex
BACKGROUND LOCATION TRACKING


The code shown in this sample gets a new location whenever the Periodic
agent runs




Windows Phone 8 supports continuous background location tracking




Every 30 minutes or so

Suitable for Run Tracking apps and Turn-by-Turn navigation

This is not covered here!


See the Location and Maps module
SHOWING A NOTIFICATION



The background task can pop up a toast notification to
deliver a message



If the user taps the message it will start up the
foreground application



Toast messages will not appear if the foreground
application is active
SCHEDULING THE BACKGROUND AGENT
DEBUGGING A BACKGROUND TASK



It would be annoying if we had to wait 30 minutes to get code in the agent
running so we could debug it



When we are debugging we can force the service to launch the agent



Such code can be conditionally compiled and excluded from the release build
WHAT WE HAVE JUST SEEN


The Location Logging application fired off a background task



The task began running even if the Location Log application is still
running in the foreground



The background task loaded location information from the phone and
added it to the log file that could then be displayed later



The background task displayed popup notifications each time that it ran
BACKGROUND AGENT TIPS


Renew often


You must reschedule agents from your foreground app at least every
two weeks



Do not implement critical functionality in a background agent





User can disable them

OS can suspend them in low battery situation

If you need more reliable execution of code outside your application and
need to update Tiles or send Toast notifications, consider Push
Notifications
REVIEW


An application can create background processes


Periodic Task tasks run every 30 minutes or so as scheduled by the OS



ResourceIntensive tasks run when the device is connected to mains
power, the battery is charged to 90% or better and the phone is not in
use




Audio Playback run alongside the application

Applications and their background processes can communicate via the local
folder which is common to both



Visual Studio can be used to debug background tasks in the same way as
foreground applications
CODE AVAILABLE IN :
WINDOWS PHONE 8 JUMPSTART: MODULE
6 BACKGROUND AGENTS DEMO
HTTP://CODE.MSDN.MICROSOFT.COM/WPAPP
S/WINDOWS-PHONE-8-JUMPSTART-

6B996D9E
Thank You

Más contenido relacionado

La actualidad más candente

A look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingA look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingMatt Lacey
 
Affordable iPhone Mobile Apps Development Services
Affordable iPhone  Mobile Apps  Development ServicesAffordable iPhone  Mobile Apps  Development Services
Affordable iPhone Mobile Apps Development ServicesGrepix Infotech Pvt. Ltd.
 
FME 2020 Unleashed: Automating
FME 2020 Unleashed: AutomatingFME 2020 Unleashed: Automating
FME 2020 Unleashed: AutomatingSafe Software
 

La actualidad más candente (6)

Apple notification push
Apple notification pushApple notification push
Apple notification push
 
A look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processingA look behind the scenes: Windows 8 background processing
A look behind the scenes: Windows 8 background processing
 
Affordable iPhone Mobile Apps Development Services
Affordable iPhone  Mobile Apps  Development ServicesAffordable iPhone  Mobile Apps  Development Services
Affordable iPhone Mobile Apps Development Services
 
Windows 8 BootCamp
Windows 8 BootCampWindows 8 BootCamp
Windows 8 BootCamp
 
FME 2020 Unleashed: Automating
FME 2020 Unleashed: AutomatingFME 2020 Unleashed: Automating
FME 2020 Unleashed: Automating
 
Intro to MonoTouch
Intro to MonoTouchIntro to MonoTouch
Intro to MonoTouch
 

Similar a WP8 Background Agents: Manage Tasks & Notifications in Visual Studio

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
 
AISEC 12 april 2012 WP 7.1.1
AISEC 12 april 2012  WP 7.1.1AISEC 12 april 2012  WP 7.1.1
AISEC 12 april 2012 WP 7.1.1Catalin Gheorghiu
 
Event oriented programming
Event oriented programmingEvent oriented programming
Event oriented programmingAshwini Awatare
 
An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)rudigrobler
 
What's new in Windows Phone Mango for Developers
What's new in Windows Phone Mango for DevelopersWhat's new in Windows Phone Mango for Developers
What's new in Windows Phone Mango for DevelopersGlen Gordon
 
Application for Data Sync Between Different geo Locations
Application for Data Sync Between Different geo LocationsApplication for Data Sync Between Different geo Locations
Application for Data Sync Between Different geo LocationsMike Taylor
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1Hussain Behestee
 
Interactive Applications in .NET
Interactive Applications in .NETInteractive Applications in .NET
Interactive Applications in .NETAndrei Fangli
 
Flutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdfFlutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdfUtibe5
 
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...DroidConTLV
 
Programming Without Coding Technology (PWCT) Getting Started - The Time Machine
Programming Without Coding Technology (PWCT)  Getting Started - The Time MachineProgramming Without Coding Technology (PWCT)  Getting Started - The Time Machine
Programming Without Coding Technology (PWCT) Getting Started - The Time MachineMahmoud Samir Fayed
 
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in FlutterDave Chao
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARSNAVER D2
 
MOBILE TO DESKTOP CONTROLLER
MOBILE TO DESKTOP CONTROLLERMOBILE TO DESKTOP CONTROLLER
MOBILE TO DESKTOP CONTROLLERPradeep Pillai
 
Code Camp - Presentation - Windows 10 - (Cortana)
Code Camp - Presentation - Windows 10 - (Cortana)Code Camp - Presentation - Windows 10 - (Cortana)
Code Camp - Presentation - Windows 10 - (Cortana)Edward Moemeka
 
MobileApplicationTesting.pptx
MobileApplicationTesting.pptxMobileApplicationTesting.pptx
MobileApplicationTesting.pptxCbhaSlide
 
Real-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppReal-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppMike Taylor
 

Similar a WP8 Background Agents: Manage Tasks & Notifications in Visual Studio (20)

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”
 
AISEC 12 april 2012 WP 7.1.1
AISEC 12 april 2012  WP 7.1.1AISEC 12 april 2012  WP 7.1.1
AISEC 12 april 2012 WP 7.1.1
 
Event oriented programming
Event oriented programmingEvent oriented programming
Event oriented programming
 
Android beginners David
Android beginners DavidAndroid beginners David
Android beginners David
 
An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)
 
Mantra
MantraMantra
Mantra
 
What's new in Windows Phone Mango for Developers
What's new in Windows Phone Mango for DevelopersWhat's new in Windows Phone Mango for Developers
What's new in Windows Phone Mango for Developers
 
Application for Data Sync Between Different geo Locations
Application for Data Sync Between Different geo LocationsApplication for Data Sync Between Different geo Locations
Application for Data Sync Between Different geo Locations
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Interactive Applications in .NET
Interactive Applications in .NETInteractive Applications in .NET
Interactive Applications in .NET
 
Flutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdfFlutter Forward EXTENDED - Ashimi0x .pdf
Flutter Forward EXTENDED - Ashimi0x .pdf
 
Voice automator
Voice automatorVoice automator
Voice automator
 
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
Will it run or will it not run? Background processes in Android 6 - Anna Lifs...
 
Programming Without Coding Technology (PWCT) Getting Started - The Time Machine
Programming Without Coding Technology (PWCT)  Getting Started - The Time MachineProgramming Without Coding Technology (PWCT)  Getting Started - The Time Machine
Programming Without Coding Technology (PWCT) Getting Started - The Time Machine
 
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in Flutter
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
 
MOBILE TO DESKTOP CONTROLLER
MOBILE TO DESKTOP CONTROLLERMOBILE TO DESKTOP CONTROLLER
MOBILE TO DESKTOP CONTROLLER
 
Code Camp - Presentation - Windows 10 - (Cortana)
Code Camp - Presentation - Windows 10 - (Cortana)Code Camp - Presentation - Windows 10 - (Cortana)
Code Camp - Presentation - Windows 10 - (Cortana)
 
MobileApplicationTesting.pptx
MobileApplicationTesting.pptxMobileApplicationTesting.pptx
MobileApplicationTesting.pptx
 
Real-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppReal-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet App
 

Más de hitesh chothani

Windows phone 8 session 13
Windows phone 8 session 13Windows phone 8 session 13
Windows phone 8 session 13hitesh chothani
 
Windows phone 8 session 11
Windows phone 8 session 11Windows phone 8 session 11
Windows phone 8 session 11hitesh chothani
 
Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9hitesh chothani
 
Windows phone 8 session 8
Windows phone 8 session 8Windows phone 8 session 8
Windows phone 8 session 8hitesh chothani
 
Windows phone 8 session 7
Windows phone 8 session 7Windows phone 8 session 7
Windows phone 8 session 7hitesh chothani
 
Windows phone 8 session 6
Windows phone 8 session 6Windows phone 8 session 6
Windows phone 8 session 6hitesh chothani
 
Windows phone 8 session 5
Windows phone 8 session 5Windows phone 8 session 5
Windows phone 8 session 5hitesh chothani
 
Windows phone 8 session 4
Windows phone 8 session 4Windows phone 8 session 4
Windows phone 8 session 4hitesh chothani
 
Windows phone 8 session 3
Windows phone 8 session 3Windows phone 8 session 3
Windows phone 8 session 3hitesh chothani
 
Windows phone 8 session 2
Windows phone 8 session 2Windows phone 8 session 2
Windows phone 8 session 2hitesh chothani
 
Windows phone 8 session 1
Windows phone 8 session 1Windows phone 8 session 1
Windows phone 8 session 1hitesh chothani
 

Más de hitesh chothani (11)

Windows phone 8 session 13
Windows phone 8 session 13Windows phone 8 session 13
Windows phone 8 session 13
 
Windows phone 8 session 11
Windows phone 8 session 11Windows phone 8 session 11
Windows phone 8 session 11
 
Windows phone 8 session 9
Windows phone 8 session 9Windows phone 8 session 9
Windows phone 8 session 9
 
Windows phone 8 session 8
Windows phone 8 session 8Windows phone 8 session 8
Windows phone 8 session 8
 
Windows phone 8 session 7
Windows phone 8 session 7Windows phone 8 session 7
Windows phone 8 session 7
 
Windows phone 8 session 6
Windows phone 8 session 6Windows phone 8 session 6
Windows phone 8 session 6
 
Windows phone 8 session 5
Windows phone 8 session 5Windows phone 8 session 5
Windows phone 8 session 5
 
Windows phone 8 session 4
Windows phone 8 session 4Windows phone 8 session 4
Windows phone 8 session 4
 
Windows phone 8 session 3
Windows phone 8 session 3Windows phone 8 session 3
Windows phone 8 session 3
 
Windows phone 8 session 2
Windows phone 8 session 2Windows phone 8 session 2
Windows phone 8 session 2
 
Windows phone 8 session 1
Windows phone 8 session 1Windows phone 8 session 1
Windows phone 8 session 1
 

Último

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 

Último (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 

WP8 Background Agents: Manage Tasks & Notifications in Visual Studio

  • 1. WP8 BACKGROUND AGENTS 1. Windows Phone task management 2. Multi-tasking with background agents 3. Creating tasks in Visual Studio 4. File transfer tasks 5. Background notifications
  • 2. FOLLOW US Twitter : @chothanihitesh Slideshare : http://www.slideshare.net/Chothani-Hitesh Email : chothani.hitesh@gmail.com Support : windows.chothani@live.com LinkedIn : in.linkedin.com/pub/hiteshchothani/6b/311/2b8 W8 Publisher : AppStudios WP Publisher : AppStudios Website : www.appmobinfotech.com
  • 3. FOREGROUND TASKS  Normally a Windows Phone application runs in the “foreground”   Has access to screen and interacts directly with the user of the phone At any given time one application is running in the foreground  Although others may be in the memory of the phone and can be selected as required  This is to ensure the best possible performance and battery life for the phone user
  • 4. BACKGROUND AGENTS  A Windows Phone application can start a “background agent” to work for it  It is a PeriodicTask, ResourceIntensiveTask or both at the same time  There is only one agent allowed per application  The agent can run when the main application is not in the foreground  An agent is not equivalent to a foreground application running in the background  It is limited in what it can do and the access it has to the processor and other phone facilities
  • 5. BACKGROUND AGENT HEALTH WARNING  The number of agents allowed to be active at one time is restricted by the Windows Phone operating system  If the right conditions do not arise for an agent it will not be started  Background agents only run in situations where the operating system feels able to give them access to the processor  If the phone goes into “Power Saver” mode it may stop running background agents completely  Users can also manage the agents running on their phone and may chose to disable them
  • 6. AGENTS AND TASKS  A Task is the scheduling type you request when you schedule a background agent to run   It is managed by the operating system which runs the agent at the appointed time There are two kinds of Tasks    Periodic tasks that are run every now and then Resource intensive tasks that run when the phone is in a position to let them The background Agent is the actual code functionality you write which runs in the background and which does the work  The agent code is implemented in a class that derives from BackgroundAgent  The class is created as part of a Scheduled Task Agent Project
  • 7. PERIODICTASK AGENTS  A PeriodicTask Agent runs every now and then   Typically every 30 minutes or so, depending on loading on the phone It is intended to perform a task that should be performed regularly and complete quickly   Memory usage allowed<= 6 MB  Unscheduled after two consecutive crashes   The agent is allowed to run for 25 seconds or so The phone sets a limit on the maximum number of active agents at any time Good for location tracking, polling background services, tile updates
  • 8. RESOURCEINTENSIVE AGENTS  Resource Intensive Agents run when the phone is in a position where it can usefully perform some data processing:   When the battery is >90% charged  When the phone is connected to WiFi   When the phone is powered by the mains When the phone is not being used (Lock screen displayed) A “resource intensive” agent can run for up to 10 minutes    Memory usage allowed<= 6 MB Unscheduled after two consecutive crashes Good for synchronisation with a host service, unpacking/preparing resources, compressing databases
  • 9. DUAL PURPOSE AGENTS  It is possible for an application to perform both periodic and resource intensive work in the background  This can be achieved using a single background agent class, run from both kinds of task  The agent will run periodically and when the phone is in a position to allow resource intensive work  When the agent starts it can determine the context in which it is running and then behave appropriately
  • 11. LOCATION TRACKER  The Location Tracker program is a simple logging application  It tracks the location of the phone by using a background agent to regularly store the location of the phone in a text log file  The agent will update the position even when the log program is not active
  • 12. CREATING A BACKGROUND AGENT  A background agent is added to the application solution as a “Scheduled Task”  There is a Visual Studio template just for this  This agent will contain the code that runs when the agent is active
  • 13. THE CAPTAINS LOG SOLUTION FILE  The solution file contains two projects  LocationLogger: the Windows Phone project which is the main application  LocationLogTaskAgent: the background agent to perform the tracking  Solutions can contain many types of different projects  When the solution is built all the assembly file outputs will be combined and sent to the phone
  • 14. CONNECTING THE AGENT PROJECT  The CaptainsLog project contains a reference to the output of the LocationTaskAgent project  The foreground application does not directly reference any objects in the agent class in code  Nonetheless, we have to explicitly link these two projects by adding a reference to the LocationTaskAgent output to the CaptainsLog project
  • 15. BACKGROUND AGENT CODE  We must implement the agent functionality in the OnInvoke method  It notifies the run time system when it has completed
  • 16. SHARING DATA WITH BACKGROUND AGENTS  First thing agent does is load the log string from isolated storage  It is going to append the current location on the end of this string
  • 17. CONCURRENT DATA ACCESS  Protect access to files in Isolated Storage by using a named Mutex  Make sure you release the mutex
  • 18. BACKGROUND LOCATION TRACKING  The code shown in this sample gets a new location whenever the Periodic agent runs   Windows Phone 8 supports continuous background location tracking   Every 30 minutes or so Suitable for Run Tracking apps and Turn-by-Turn navigation This is not covered here!  See the Location and Maps module
  • 19. SHOWING A NOTIFICATION  The background task can pop up a toast notification to deliver a message  If the user taps the message it will start up the foreground application  Toast messages will not appear if the foreground application is active
  • 21. DEBUGGING A BACKGROUND TASK  It would be annoying if we had to wait 30 minutes to get code in the agent running so we could debug it  When we are debugging we can force the service to launch the agent  Such code can be conditionally compiled and excluded from the release build
  • 22. WHAT WE HAVE JUST SEEN  The Location Logging application fired off a background task  The task began running even if the Location Log application is still running in the foreground  The background task loaded location information from the phone and added it to the log file that could then be displayed later  The background task displayed popup notifications each time that it ran
  • 23. BACKGROUND AGENT TIPS  Renew often  You must reschedule agents from your foreground app at least every two weeks  Do not implement critical functionality in a background agent    User can disable them OS can suspend them in low battery situation If you need more reliable execution of code outside your application and need to update Tiles or send Toast notifications, consider Push Notifications
  • 24. REVIEW  An application can create background processes  Periodic Task tasks run every 30 minutes or so as scheduled by the OS  ResourceIntensive tasks run when the device is connected to mains power, the battery is charged to 90% or better and the phone is not in use   Audio Playback run alongside the application Applications and their background processes can communicate via the local folder which is common to both  Visual Studio can be used to debug background tasks in the same way as foreground applications
  • 25. CODE AVAILABLE IN : WINDOWS PHONE 8 JUMPSTART: MODULE 6 BACKGROUND AGENTS DEMO HTTP://CODE.MSDN.MICROSOFT.COM/WPAPP S/WINDOWS-PHONE-8-JUMPSTART- 6B996D9E