.NET Zone is brought to you in partnership with:

Robert is a South African technology specialist with focus on Microsoft technologies. He is very passionate about teaching and sharing and is a Microsoft MVP & Ranger. Robert is a DZone MVB and is not an employee of DZone and has posted 75 posts at DZone. You can read more from them at their website. View Full User Profile

Windows Store App Development: What Do You Get From Being A Lock Screen App?

10.20.2012
| 2451 views |
  • submit to reddit

When you start with development of Windows Store apps, you may want to run tasks in the background and an important aspect of that is deciding if you want to be a lock screen app or not.  Microsoft has a guide on this, which is ESSENTIAL reading so this post should be seen as a cheat sheet for a portion of that document.

Triggers

Background tasks kick off on a trigger so what triggers can lock screen & non-lock screen apps use. Non-lock screen apps can run background tasks based on

Background task trigger type

Trigger event

When the background task is triggered

MaintenanceTrigger

MaintenanceTrigger

It’s time for maintenance background tasks.

SystemEventTrigger

InternetAvailable

The Internet becomes available.

SystemEventTrigger

LockScreenApplicationAdded

An app tile is added to the lock screen.

SystemEventTrigger

LockScreenApplicationRemoved

An app tile is removed from the lock screen.

SystemEventTrigger

NetworkStateChange

A network change such as a change in cost or connectivity occurs.

SystemEventTrigger

OnlineIdConnectedStateChange

Online ID associated with the account changes.

SystemEventTrigger

ServicingComplete

The system has finished updating an application.

SystemEventTrigger

SessionDisconnected

The session is disconnected.

SystemEventTrigger

SmsReceived

A new SMS message is received by an installed mobile broadband device.

SystemEventTrigger

TimeZoneChange

The time zone changes on the device (for example, when the system adjusts the clock for daylight saving time).

Lock screen apps can use those and much more, the extra triggers for lock screen apps are

Background task trigger type

Trigger event

When the background task is triggered

ControlChannelTrigger

ControlChannelTrigger

On incoming messages on the control channel.

PushNotificationTrigger

PushNotificationTrigger

A raw notification arrives on the WNS channel.

SystemEventTrigger

ControlChannelReset

A network channel is reset.

SystemEventTrigger

SessionDisconnected

The session is disconnected.

SystemEventTrigger

UserAway

The user becomes absent.

SystemEventTrigger

UserPresent

The user becomes present.

TimeTrigger

TimeTrigger

A time event occurs.

CPU

Now we know when the background task will happen, how much CPU can background task consume during it’s execution is also affected by lock screen & non-lock screen.

Before we look at the table there is three things to know:

  • This is per app – NOT per background task!
  • Think of the refresh period as the point were we get filled up with more resources. So you can run multiple background tasks and they all consume from the pool of resources. At the refresh period the bucket is filled & any unused time will be lost.
  • CPU second is not the same as a real second. A CPU second is the amount of time that is consumed by the CPU – so if you are doing I/O (like a download) then it is not counted.

 

CPU resource quota

Refresh period

Lock screen app

2 CPU seconds

15 minutes

Non-lock screen app

1 CPU second

2 hours

Bandwidth

In a similar way to CPU the amount of data you can consume is also effected by being a lock screen app, but in addition to that the average speed of your internet also effects the amount of data. There is another difference to CPU, rather than one bucket – there is two:

  • Small period: The shorter amount of time and has a small amount it can be downloaded.
  • Day: The max per day – so accumulation of all the smaller ones cannot exceed this.

The table below has 1Mb & 10Mb as the average speed options but you could think of them as 1Mb = WiFi and 10Mb plugged into a network. These amounts are the top end, so if the network is slow you get less.

Average throughputLock screen appsNon-lock screen apps
Every 15minPer dayEvery 2 hoursPer day
1Mb/s0.469Mb4.69Mb0.625Mb7.5Mb
10Mb/s4.69Mb450Mb6.25Mb75Mb

Global Pool

Above we have looked at the resource constraints for CPU & bandwidth but what happens if that isn’t enough? Windows has a global pool of additional CPU & bandwidth resources that are shared system wide. This means that if you need 2.5CPU seconds you will likely get it! However the global pool is shared across all the apps, so it is not guaranteed (the above resources we have looked at are guaranteed). So if you have some abusive apps that use it, then your app may not get anything from the global pool. The global pool is replenished every 15min.

You can test your app works with an empty global pool, and you really should do this, by turning it off in the registry

Value name

Type

Default value

Description

HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\Windows NT\CurrentVersion\BackgroundModel\Policy\CpuEnableGlobalPool

DWORD

1

Controls the CPU global pool. A value of zero disables CPU global pool.

HKEY_LOCAL_MACHINE\ SOFTWARE\Microsoft\Windows NT\CurrentVersion\BackgroundModel\Policy\NetEnableGlobalPool

DWORD

1

Controls the network global pool. A value of zero disables network global pool.

Published at DZone with permission of Robert Maclean, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)