\r\n\r\n","bodyAsHTML":"Windows 8 apps are like a stack of cards. Only the top card is active\r\n – the rest (apps) have their threads suspended. Windows 8 snap view \r\nactually allows for two active apps. That’s pretty cool.

Here’s what you need to know:

Background tasks

Some\r\n developers need to run code when apps are not running. For this, there \r\nis the background task. These are periodic and have constrained CPU and \r\nNetwork usage.

There are two types of background tasks: standard\r\n and lock screen tasks. There can be only 7 lock screen tasks, and the \r\nkey difference is the constraint thresholds.

CPU quota

The\r\n first type of quota is CPU time; this is not clock time. It \r\ndramatically impacts battery life. However, this CPU quota is enforced \r\non battery and on AC power.

Every two hours a standard task is \r\ngranted 1 CPU second to complete its work. If it fails to finish, it is \r\nsuspended until more time is given. Lock screen tasks are granted 2 CPU \r\nseconds every 15 seconds.

MSDN:\r\n An app on the lock screen receives a certain amount of CPU time at \r\nregular intervals for its background tasks. If the app uses all of its \r\navailable CPU time, its background tasks are suspended until the app’s \r\nCPU quota is replenished at the next generation for CPU quota updates.

Network quota

The\r\n second type of quota is Network bandwidth. Like CPU time, network \r\nconsumption dramatically impacts battery life. However, Network quotas \r\nare only enforced when on battery.

First, quota amounts vary by \r\nbandwidth. Assuming 10Mbps, lock screens get 45 MB a day. Standard \r\nbackground tasks only get 7.5 MB a day.

More than one

A\r\n Windows 8 app can easily have than one background task. However, all \r\nWindows 8 app background tasks split the quotas of CPU and network \r\nbandwidth.

Custom code

Push notifications handle \r\nbackground tile updates for apps. The playback manager handles \r\nbackground audio for apps. The background transfer API handles \r\ndownloading and uploading for apps. Share contracts handle sharing code \r\nbetween apps. And, background tasks can execute custom code.

Phone home

Not\r\n so long ago SETI began its sweep of the heavens. The resulting tidal \r\nwave of data needed to be processed to look for patterns in the night \r\nsky. To accomplish this, volunteers installed the SETI screensaver to \r\nprocess blocks of data while the user was away. It was brilliant.

This\r\n is an example of a terrible use of Windows 8 background tasks. Not only\r\n are Windows 8 background tasks limited in their network traffic, but \r\nwith just 1 or 2 CPU seconds, the amount of processing is constrained to\r\n prevent heavy processor / battery consumption.

Lock screen

So,\r\n you wanna be a lock screen task? You need to remember one thing. The \r\nuser is in charge. You can programmatically add your app to the lock \r\nscreen. But the user can snap you back so hard you’ll think you’re a \r\nfirst year cadet again. So don’t get too high and mighty.

MSDN:\r\n An app can register to be notified when it is added or removed from the\r\n lock screen by registering a background task with the \r\nLockScreenApplicationAdded or LockScreenApplicationRemoved triggers \r\nprovided in the SystemTrigger class.

Self-promotion

Oh,\r\n yes you can! An app can programmatically add itself to the lock screen \r\nby using the BackgroundExecutionManager class – something like “await \r\nBackgroundExecutionManager.RequestAccessAsync()”. But don’t be slippery \r\nabout it; this type of code needs to be in a button click handler (or \r\nsome user-induced event handler).

Sharing data

The UI \r\napp might have something the background app needs. Then again. The \r\nbackground app might want to hand something to the UI app. The best and \r\nmost reliable approach is to use persistent storage – such as the \r\nisolated folders that the tasks and UI apps share in common.

Note: No matter what, do NOT communicate directly. It’s nothing but trouble!

Trigger me this

It\r\n is necessary for a task to be based on exactly one trigger. These are \r\nthe causes for the task to be invoked. And here’s the list: \r\nControlChannelTrigger, MaintenanceTrigger, PushNotificationTrigger, \r\nInternetAvailable, LockScreenApplicationAdded, \r\nLockScreenApplicationRemoved, ControlChannelReset, NetworkStateChange, \r\nOnlineIdConnectedStateChange, ServicingComplete, SessionConnected, \r\nSessionDisconnected, SmsReceived, TimeZoneChange, UserAway, UserPresent,\r\n TimeTrigger

Similar to triggers are conditions. A task may \r\ninclude zero or more conditions to filter its execution. And here’s the \r\nlist: InternetAvailable, InternetNotAvailable, SessionConnected, \r\nSessionDisconnected, UserNotPresent, UserPresent.

If your task \r\nis based on the TimeTrigger then you might only want to execute when \r\nInternetAvailable. That makes sense. Combining the condition with the \r\ntrigger removes the need to spin up your task or for your task to reach \r\nout and test for the condition.

Not for everyone

But \r\nwait, the gulf between the top 1% and the rest of us is getting wider. \r\nNot all triggers and not all triggers and conditions are available to \r\nstandard tasks. Here’s the list of lock screen only triggers: \r\nTimeTrigger, PushNotificationTrigger, ControlChannelTrigger. And, here’s\r\n the list of lock screen only conditions: SessionConnected, UserPresent,\r\n UserAway and ControlChannelReset.

Latching on?

An \r\nimportant concept is latching. This is where the trigger occurs (like, \r\ntime) but the condition is false. In this case, the trigger is latched \r\n(so to speak). At the moment when the condition is met, it is not \r\nrequired that the trigger fire again – the trigger is raised and the \r\ntask is executed immediately.

Cancel

At any point for \r\nexecution and for a million reasons (such as Connected Standby), the \r\noperating system can request that a task cancel. That gives you 5 \r\nseconds to comply. If you do, then it is happiness. If you do not, then \r\nthe OS will forcibly terminate your task.

Windows Phone

Like\r\n so many things in Windows 8, if you are a Windows Phone developer you \r\nhave a tremendous head start in understanding the lifecycle and \r\nbackground task architecture of Windows 8. It’s amazingly similar. \r\nRegistering your task is almost identical – use BackgroundTaskBuilder.

Like\r\n Windows Phone, tasks are class libraries (marked as WinMD) implementing\r\n IBackgroundTask’s Run() method where all the work takes place. It’s \r\nreally that easy. Here are some serious resources to get you started.

Best of luck!

\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n","author":{"id":954995,"username":"Jerry Nixon","realname":null,"emailHash":"1679f0ca80c657f1fca8fbcc74eeefe1","avatar":"https://secure.gravatar.com/avatar/1679f0ca80c657f1fca8fbcc74eeefe1?d=identicon&r=PG","reputation":0},"activeRevisionId":540022,"revisionIds":[540022,540021],"lastActiveUserId":954995,"lastActiveDate":1346804911000,"parentId":null,"parentAuthor":null,"originalParentId":null,"childrenIds":[],"commentIds":[],"marked":true,"topics":["mobile","tips and tricks","windows phone","windows 8","lock screen"],"primaryContainerId":8,"containerIds":[7,8],"plug":"windows-8-scheduled-tasks-lock","wiki":false,"score":0,"depth":0},"enableThreadedComments":true,"portal":{"topic":{"id":"29","type":"topic","creationDate":1434655010000,"creationDateFormatted":"06/18/2015 07:16 PM","name":"mobile","createdBy":{"id":2,"username":"matt"},"parentTopics":[],"childTopics":[],"usedCount":36109},"blurb":"Mobile App developer news, tools and training resources from DZone, the trusted source for advanced software design, web development and devops best practices.","code":"mobile","id":9,"creationDate":1434673929000,"creationDateFormatted":"06/19/2015 12:32 AM","displayTitle":"Mobile Zone: Mobile app development news, tutorials & tools","title":"Mobile","new":false,"order":9,"shortTitle":"mobile-app-developer-tutorials-tools-news","color":"yellow","pageTitle":"Mobile App Development News, Tools & Training - DZone","active":true,"modificationDate":1437510259000,"modificationDateFormatted":"07/21/2015 08:24 PM"},"contentType":"article"}],"loadedStyles":[["/lib/bootstrap/bootstrap.less","/lib/font-awesome/font-awesome.less","/lib/fontello/css/fontello.css","/lib/fontello/css/animation.css","/lib/angular-ui/select.css","/lib/ngDialog/css/ngDialog.css","/less/ngDialog-theme.less","/lib/bootstrap-switch/bootstrap-switch.css","/less/dzone20.less","/less/fonts.less","/less/directives.less","/lib/slick/slick.css","/lib/bootstrap-slider/bootstrap-slider.css","/less/layout.less","/widgets/article/content/article-content.less","/widgets/article/infoBar/widget.less","/widgets/components/slider/widget.less","/widgets/content/commentsSlider/widget.less","/widgets/header/blackBar/widget.less","/widgets/header/main/header-common.less","/widgets/header/main/widget.less","/widgets/sidebar/content/list/list.less","/widgets/sidebar/tapBar/sidebar-list.less","/widgets/sidebar/tapBar/widget.less","/widgets/users/UserHomeMiniProfile/widget.less"]],"loadedScripts":[["/lib/jquery/jquery.js","/lib/lodash/lodash.js","/lib/moment/moment.js","/scripts/utils.js","/lib/angular/angular.js","/lib/angular/angular-sanitize.js","/lib/local-storage/angular-local-storage.js","/lib/angular-ui/bootstrap.js","/lib/angular-ui/select.js","/lib/bootstrap-switch/bootstrap-switch.js","/lib/ngDialog/js/ngDialog.js","/lib/angular-moment/angular-moment.js","/scripts/app.js","/scripts/socket.js","/scripts/services.js","/scripts/ui-services.js","/scripts/directives.js","/scripts/filters.js","/lib/angular-touch/angular-touch.min.js","/lib/elastic/elastic.js","/lib/ng-file-upload/angular-file-upload-all.js","/lib/angular-deckgrid/angular-deckgrid.js","/scripts/dzone.js","/scripts/ads.js","/scripts/head.js","/scripts/links.js","/scripts/utilities/directives.js","/scripts/utilities/services.js","/scripts/utilities/image-editor.js","/lib/bootstrap-slider/bootstrap-slider.js","/lib/bootstrap-slider/directive.js","/lib/angular-draganddrop/draganddrop.js","/widgets/article/content/utils.js","/widgets/article/infoBar/services.js","/widgets/components/slider/service.js","/widgets/header/main/angulartics-ga.js","/widgets/header/main/angulartics.js","/widgets/header/main/resize.js","/widgets/sidebar/content/list/service.js","/widgets/sidebar/tapBar/directive.js","/widgets/sidebar/tapBar/service.js"]],"TH_CSRF":"-8703920125540163538","botInfo":[{"isRenderBot":false}],"request":[{"site":{"id":7,"title":"DZone: Programming & DevOps news, tutorials & tools","keywords":"programming, software development, devops, java, agile, web, iot, database, mobile, big data, cloud","description":"Programming, Web Development, and DevOps news, tutorials and tools for beginners to experts. Hundreds of free publications, over 1M members, totally free.","name":"DZone.com"},"dev":false,"cdn":["dz2cdn1.dzone.com","dz2cdn2.dzone.com","dz2cdn3.dzone.com","dz2cdn4.dzone.com"],"theme":"dz20","context":"","user":{"id":2500002,"authenticated":false,"name":"Anonymous","realName":null,"avatar":"https://secure.gravatar.com/avatar/?d=identicon&r=PG","profile":"/users/2500002/anon-user.html"}}],"portals":[[{"topic":8,"id":2,"shortTitle":"agile-methodology-training-tools-news","color":"red","name":"Agile","code":"agile","url":"/agile-methodology-training-tools-news"},{"topic":6129,"id":3,"shortTitle":"big-data-analytics-tutorials-tools-news","color":"green","name":"Big Data","code":"big-data","url":"/big-data-analytics-tutorials-tools-news"},{"topic":30,"id":4,"shortTitle":"cloud-computing-tutorials-tools-news","color":"orange","name":"Cloud","code":"cloud","url":"/cloud-computing-tutorials-tools-news"},{"topic":59,"id":5,"shortTitle":"database-sql-nosql-tutorials-tools-news","color":"purple","name":"Database","code":"database","url":"/database-sql-nosql-tutorials-tools-news"},{"topic":31,"id":6,"shortTitle":"devops-tutorials-tools-news","color":"yellow","name":"DevOps","code":"devops","url":"/devops-tutorials-tools-news"},{"topic":1138,"id":7,"shortTitle":"enterprise-integration-training-tools-news","color":"green","name":"Integration","code":"integration","url":"/enterprise-integration-training-tools-news"},{"topic":48,"id":8,"shortTitle":"iot-developer-tutorials-tools-news-reviews","color":"orange","name":"IoT","code":"iot","url":"/iot-developer-tutorials-tools-news-reviews"},{"topic":1,"id":1,"shortTitle":"java-jdk-development-tutorials-tools-news","color":"purple","name":"Java","code":"java","url":"/java-jdk-development-tutorials-tools-news"},{"topic":29,"id":9,"shortTitle":"mobile-app-developer-tutorials-tools-news","color":"yellow","name":"Mobile","code":"mobile","url":"/mobile-app-developer-tutorials-tools-news"},{"topic":653,"id":10,"shortTitle":"apm-tools-performance-monitoring-optimization","color":"red","name":"Performance","code":"performance","url":"/apm-tools-performance-monitoring-optimization"},{"topic":35,"id":11,"shortTitle":"web-development-programming-tutorials-tools-news","color":"orange","name":"Web Dev","code":"webdev","url":"/web-development-programming-tutorials-tools-news"}]],"matchedUrl":{"name":"dzone:articles:view","mapping":"/articles/**","mappingPatterns":{}},"requiresModule":["angulartics","angulartics.google.analytics","dndLists","generalDirectives","monospaced.elastic","angularFileUpload","akoenig.deckgrid","ui.bootstrap-slider","ngSanitize","ui.select","ui.bootstrap","angularMoment","ngTouch","ngDialog","LocalStorageModule"]}; } catch(e) { console.error(e); }
4
Notification
  • Adam Van Grack started following you

  • Jessica Conaghan, Gumption Scott and 6 commented on a link you posted

    T-Mobile Unvells Cheaper, More Basic 'Simple Prepaid' Phone Plans

  • Jessica Conaghan replied on a comment you posted

    CSS counters are one of those "oh neat, didn't know CSS could do that" features with a lot of Xubuntu 14.10 Utopic Unicorn is the latest release of xubuntu based on Ubuntu 14.10

  • Jessica Conaghan started following you

See All
POWERED BY DZone TeamHub
\r\n\r\n","source":"http://blog.jerrynixon.com/2012/08/windows-8-scheduled-tasks-lock-screen.html?","views":4434,"articleDate":1346804911000,"tldr":null,"originalSource":"http://blog.jerrynixon.com/2012/08/windows-8-scheduled-tasks-lock-screen.html?","published":true,"nComments":0,"articleType":""}]; WMODEL_DATA.perms = {"canDecidePick":false,"canPublish":false}; WMODEL_DATA.isPreview = false; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('article.content', 'articleContent7', WMODEL_DATA, typeof controller == 'function' ? controller : null, [{name: 'partners', data: true},{name: 'DEFAULT', data: true}], ' oUhbblYOaqbcblYOaqbcC', null); })(); (function() { function controller($scope, $service, $location, SideBarService, TH$Request) { SideBarService.ctx.pageSize = $scope.pageSize; SideBarService.ctx.isPreview = $scope.isPreview; SideBarService.ctx.mode = $scope.mode; SideBarService.fn.loader = $service; SideBarService.fn.scrollCheck = function() { $scope.$emit('thIfScrollCheck'); }; var currentFilter; $scope.$on('$locationChangeSuccess', function() { if (!$location.search().filter) { $scope.filter = 'latest'; } else { $scope.filter = $location.search().filter; if ($scope.filter == 'latest') { $location.search('filter', null); } } if (currentFilter == $scope.filter) { return; } currentFilter = $scope.filter; SideBarService.ctx.filter = $scope.filter; }); $scope.display = SideBarService.getList(); $scope.$watchCollection(function() { return SideBarService.getList(); }, function (n) { $scope.display = n; }); $scope.isActive = SideBarService.isActive; $scope.isExcluded = SideBarService.isExcluded; $scope.loadMore = SideBarService.load; $scope.loading = function() { return SideBarService.ctx.loading; } } var WMODEL_DATA = {}; WMODEL_DATA.pageSize = 20; WMODEL_DATA.isPreview = false; WMODEL_DATA.OPTIONS = {}; WMODEL_DATA.mode = null; TH.installWidgetController('sidebar.content.list', 'sidebarContentList10', WMODEL_DATA, typeof controller == 'function' ? controller : null, [{name: 'DEFAULT', data: true}], ' oUhbkSMaaqbcdvVkcC', null); })(); (function() { var WMODEL_DATA = {}; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('sidebar.tapBar', 'sidebar', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhbkSMadabfWVcC oUhbkSMadabbWQbVkcC', null); })(); (function() { function controller($scope, shareThis, TH$Dialog, TH$Service) { $scope.getEditUrl = function(id, type) { if (!type || type == 'article') { return '/content/' + id + '/edit.html'; } else { return '/dzone/staff/' + type + (type == 'refcard' ? 'z' : 's') + '/' + id + '/edit.html'; } } $scope.share = function(socialNet, url, title){ shareThis.shareThis(socialNet, url, title); }; $scope.canDelete = function(article) { return article.canDelete; } $scope.edit = function(link) { TH$Dialog.open({ loadWidget: 'links.postPreview', widgetArgs: { edit: link.id }, size: 'xbig' }).then(function (result) { $scope.link.title = result.title; $scope.link.linkDescription = result.content; $scope.link.thumb = result.thumb; $scope.link.tags = result.topics; }); }; $scope.deleteLink = function(article) { var title = article.title; var type = 'link'; if(article.header){ title = (article.header.type == 'article') ? article.header.title : article.title; type = (article.header.type == 'article') ? 'article' : 'link'; } TH$Dialog.confirm('Do you want to delete "' + title + '"?').then(function() { return TH$Service.action('delete', {type: type, id: article.id}); }).then(function() { article.deleted = true; }); }; } var WMODEL_DATA = {}; WMODEL_DATA.OPTIONS = {}; TH.installWidgetController('content.commentsSlider', 'contentCommentsSlider9', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhbaqbcaibvnWffWVcC', null); })(); (function() { var WMODEL_DATA = {}; WMODEL_DATA.name = "commentsSlider"; WMODEL_DATA.slot = null; WMODEL_DATA.OPTIONS = {"name":"commentsSlider"}; TH.installWidgetController('components.slider', 'componentsSlider8', WMODEL_DATA, typeof controller == 'function' ? controller : null, null, ' oUhballbvbdSaoUhM', null); })();