Sinergija 11 WP7 Mango multitasking and “multitasking”

26
WP7 Mango multitasking and “multitasking” Cătălin Gheorghiu October 20, 2011

Transcript of Sinergija 11 WP7 Mango multitasking and “multitasking”

Page 1: Sinergija 11   WP7 Mango multitasking and “multitasking”

WP7 Mango multitasking and “multitasking”Cătălin Gheorghiu

October 20, 2011

Page 2: Sinergija 11   WP7 Mango multitasking and “multitasking”

Agenda

• What we will not talk about• What is multitasking or the great picture• WP 7 multitasking or life ain’t fair• WP 7 Application Lifecycle or our case• Mango dormant state or the novelty• Mango background task or the news• Q&A

Page 3: Sinergija 11   WP7 Mango multitasking and “multitasking”

What we will not talk about &What is multitasking or the great picture

Page 4: Sinergija 11   WP7 Mango multitasking and “multitasking”

WP 7 multitasking or life ain’t fair

Page 5: Sinergija 11   WP7 Mango multitasking and “multitasking”

WP 7 multitasking

• The Windows Phone platform uses a multi-tasking operating system (so far so good)

• However, this multi-tasking ability is not extended to applications that we write (small print at the bottom)

• Although we can have something that can run in the background (a solution)

Page 6: Sinergija 11   WP7 Mango multitasking and “multitasking”

WP 7 Application Lifecycle or our case

Page 7: Sinergija 11   WP7 Mango multitasking and “multitasking”

Application Lifecycle

http://msdn.microsoft.com/en-us/library/ff817008(v=vs.92).aspx

Page 8: Sinergija 11   WP7 Mango multitasking and “multitasking”

Application Lifecycle

Page 9: Sinergija 11   WP7 Mango multitasking and “multitasking”

Application Lifecycle

<Application.ApplicationLifetimeObjects>

<shell:PhoneApplicationService

Launching="Application_Launching" Closing="Application_Closing"

Activated="Application_Activated“ Deactivated="Application_Deactivated"/>

</Application.ApplicationLifetimeObjects>

Page 10: Sinergija 11   WP7 Mango multitasking and “multitasking”

Demo(s)

Page 11: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango dormant state or the novelty

Page 12: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango dormant state

• An application will receive events to notify it of changes to state (same for tombstone and dormant)

• It can also use status information when it resumes (to know if tombstone or dormant)

• It has access to memory space to save transient state and isolated storage to persist application state (does not know if is going to sleep or put to sleep)

• Beware an app even dormant could very well not get activated again

Page 13: Sinergija 11   WP7 Mango multitasking and “multitasking”

Demo(s)

Page 14: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background task or the news

Page 15: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background state

• A Windows Phone application can start ONE “background agent” to work for it (with limitations in what it can do and the access it has to the processor and other phone facilities).Think about them as app own shadow windows service– It is a PeriodicTask, ResourceIntesiveTask or both at

the same time• 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

Page 16: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background state

• 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 or will stop running– 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

Page 17: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background state

• A Task is the container that is managed by the operating system and runs at the appointed time and it runs an Agent which is the actual code payload which does the work– The agent code is called as a method in a class– The class is created as part of a Scheduled Task Agent

Project• There are two kinds of Task

– Periodic tasks that are run every now and then– Resource intensive tasks that run when the phone is in

a position to let them

Page 18: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background task

• 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 (is allowed to run for 15 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

Page 19: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background state

• Resource Intensive Agents run when the phone is in a position where it can usefully perform some data processing (but up to 10 minutes):– When the phone is powered by the mains– When the phone is connected to WiFi– When the phone is not being used (Lock screen

displayed)• Good for synchronization with a host service,

unpacking/preparing resources, compressing databases

Page 20: Sinergija 11   WP7 Mango multitasking and “multitasking”

Mango background task

• It is possible for an application to perform both periodic and resource intensive work in the background (remember just ONE Agent per app)

• 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

Page 21: Sinergija 11   WP7 Mango multitasking and “multitasking”

Demo(s)

Page 22: Sinergija 11   WP7 Mango multitasking and “multitasking”

Q&A

Page 23: Sinergija 11   WP7 Mango multitasking and “multitasking”

Thank you for yourattention.Contact:• My Blog http://ronua.ro/CS/blogs/catalin/default.aspx• My Email [email protected]

Page 24: Sinergija 11   WP7 Mango multitasking and “multitasking”

Microsoft Serbia and MT:S proudly presents...

WP7 prize contest

• Contest will start in October and will be finished in December

• Prizes: 4 Windows Phone handsets, Microsoft hardware!

• Apps will be published on Marketplace

• More info after Sinergija at Sinergija portal, microsoft.com/serbia and msacademic.rs

• Follow @mssinergija, @MicrosoftSrbija or @msacademic

• CREATE. WIN. HAVE FUN.

Page 25: Sinergija 11   WP7 Mango multitasking and “multitasking”

Microsoft and Open Source

gateway for deeper exploration of open

source engagements

http://www.microsoft.com/openness

Port25blogs from the

platform community and the OSS Lab

teams http://Port25.technet.com

Codeplexresources for

developers and consumers of open

source projectshttp://www.codeplex.com

Interoperability Bridgestechnical

collaborative works http://www.interoperabilitybridges.com

Open Upcross-Industry

Interoperability and Standards activitieshttp://www.microsoft.com/interop/openup

Shared Sourceportal for

programmatically sharing code

http://www.microsoft.com/sharedsource

ODataopen source starter

kit for Internet publishing of

Government datasets using the Open Data

http://ogdisdk.cloudapp.net

Open Specprotocols, file

formats, standards, technical

specificationshttp://www.microsoft.com/openspecifications

BizSparkProgram for Start-Up

companies from both commercial and open source

backgroundshttp://www.microsoft.com/bizspark

Openness and Interoperability @Microsoft

How can I receive up-to-date Openness announcements from Microsoft?In addition to the websites above, you can receive regular updates to Microsoft’s openness, interoperability and standards efforts via the following channels:• http://blogs.technet.com/b/openness/ • http://blogs.msdn.com/b/interoperability/ • http://twitter.com/OpenAtMicrosoft • http://port25.technet.com • http://channel9.msdn.com/Blogs/Interoperability

Page 26: Sinergija 11   WP7 Mango multitasking and “multitasking”

Help us choose the best Sinergija lecturer! Telekom

Srbija and Microsoft will award you – at the conference end, we’ll give one HTC Mozart WP7 phone to someone from

the audience – randomly.

Go to www.mssinergija.net, log in and cast your votes.

Please rate this lecture

and WIN HTC MOZART!

You can rate only lectures that you were present at, just once. More lectures you rate, more chances you have.Please use computers at the front of this room, or rate lecture from your phone or home computer, at Sinergija

portal. This prize contest will end at Thursday, October 20th at 9 PM. Winner will be announced at the official Sinergija web

portal, www.mssinergija.net

is a friend of Sinergija 2011 Conference and Imagine Cup student competition in Serbia.