Background task sample

This sample shows you how to create and register background tasks using the Windows Runtime background task API.

4.2 Star
57,916 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Not working on a device
    1 Posts | Last post January 29, 2015
    • The sample works great in the emulator but when I try to run it on my Lumia 1020 running 8.10.14157.200 it doesn't work.  I tried the SampleBackgroundTask and SampleBackgroundTaskWithCondition (as they are the easiest to trigger quickly) with the TimeZoneChange event, as well as UserAway, NetworkStateChange, etc... but it never updates the progress like it does in the emulator.
  • Background task registration does not work
    1 Posts | Last post October 21, 2014
    • Windows 8.1 / VS 2013 Update 3. 
      Attempting to register the Javascript background task results in an exception.See exception trace below. 
      Please suggest a fix.
      		description	"The specified path is invalid.\r\n"	String
      		message	"The specified path is invalid.\r\n"	String
      		number	-2147024735	Number
      		stack	"WinRTError: The specified path is invalid.\r\n\n   at registerBackgroundTask (ms-appx://microsoft.sdksamples.backgroundtask.js/js/global.js:60:9)\n   at registerJavaScriptBackgroundTask (ms-appx://microsoft.sdksamples.backgroundtask.js/js/scenario1_JavascriptBackgroundTask.js:19:9)"	String
  • first launch app to register backgroud task.
    2 Posts | Last post April 09, 2013
    • Hi,
      This example work fine for me.But i see in the code , we need to regist backgroud task by clicking on button register.So it mean we need to launch the app and click on button to regist. is there a way when we install app then it automatic to regist backgroud task ?
      Thanks in advance.
    • Hi Le Huu.  There currently no way to register background tasks at application install time.
  • code snippet wrong in backgroundtask doc
    2 Posts | Last post November 08, 2012
    • In the C# code snippet in the background tasks doc, it is missing the "myTaskBuilder.S​etTrigger(myTri​gger);" line. The snippet has the the TimeTrigger in it.
      This is a follow up to my other post "does not fire the TimeTrigger" which Bob Bao is looking into.
      Also, if there is a better way to test a TimeTrigger, other than wait 15 minutes, that would be very useful. For example, it could fire once within a minute and 15 minutes afterward. This would help debugging a lot.
    • Hi RobHogue,
      You can start a registered background task earlier than 15 minutes on Visual Studio. Start your app, let it register the task, and open a menu where probably its current item is "Suspend", next to the Process information. Click the downarrow and you should see your task name on the menu. Just click on it to run!
  • BackgroundTask Run method not fired
    3 Posts | Last post September 26, 2012
    • Hi, 
      I am using background task in C# development environment when i start my app the Run method inside the class is not fired, in the manifest i define the settings like :
              <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTaskWorker.LocationBackgroundTask">
                  <Task Type="timer" />
      My Run method is inside my LocationBackgroundTask class , and the control is not coming in this class to hit the Run method.
    • always followed this procedure.
    • Hi as it is defined in the sample i proceed with that way so my problem is very first time when we are registering the background task its registering and hitting the Run method also but not consistently, i run the sample for Geo Location Tracking inside that when the app is suspended in background we are tracking the location so in sample also the Run method is not fired consistently so i am unable to track the location If u have any idea please share ?
  • What shows that the task executed
    1 Posts | Last post June 27, 2012
    • Did everything exactly as in the whitepaper, ran the c# code, registered the task in the sample, set the task on the lock screen as a background task, changed the UTC time zone and waited both at the lock screen and logged in. Nothing happened.
      What is meant to happen, am I meant to get a notification, popup, update on the notification sample screen? 
      Has anyone got this to work and if so how did you know?
  • Can't get javascript task to run?
    1 Posts | Last post June 24, 2012
    • I'm trying to 'see' the results of my test javascript background test working, but so far drawing a blank.
      A look at the background tasks diagnostics is showing this :
      A background task with entry point js\fbBackgroundTask.js and name FacebookBackgroundTask has been unregistered because the entry point no longer exists in the task's application package.
      Any ideas? I have my js\fbBackgroundTask.js in the application manifest pointing to the entry point, and set as the 'start page' for a timer event (I want to run this every x mins - is it true the minimum you can set is 15 mins?!).
      Any ideas what this message means?
  • I realize that MS hates to support VB, but ...
    2 Posts | Last post June 12, 2012
    • if you're going to have VB samples, at least test them for some functionality. I read the whole whitepaper on background tasks trying to figure out what was wrong, and then noticed that UpdateBackgroundTaskUI is using IS to compare two strings. It does seem to work if we use = instead.
    • Hi Dave,
      Which version of the sample are you looking at?  I downloaded the one located above and I no longer see a "UpdateBackgroundTaskUI" method in the implementation.
  • How to identify whether a background task is executed or not.
    2 Posts | Last post June 12, 2012
    • I have downloaded this sample application for C++. I launched the sample application from Visual Studio-11 on Win8. In the application UI, I select "1) Sample background task" and then click "Register". This mentions "Registers a background task for the Time Zone Change system event. The background task runs whenever the Time Zone changes."
      After this I go to the Desktop and then select "Change date and time settings..." and then change the Time Zone and press "OK".
      How do I know that the background task is launched? I do not see any application getting launched after I press "OK" for Time Zone change. If I go back to the sample application, I do not see any update on the UI as well. Is the background task logging any information somewhere? How do I know that?
    • Hi Himanshu,
      A couple things that you should be able to use to troubleshoot your problem.
      1. Ensure that when you change your timezone you change to one that has a different UTC offset.  The task will only fire if the system clock changes due to the time zone change.
      2. You can set breakpoints in the Tasks::SampleBackgroundTask.Run method to verify that they are running, you should also see UI updates in the output portion of the sample from progress and completion callbacks.
  • C++
    4 Posts | Last post January 30, 2012
    • Can C++ be used for creating a background task? Should a background task object be implemented as a WinRT component? Is there anything that is different for C++ implementations that should be noted?
    • The answer to my own question is yes to build a background task object in C++ you create a WinRT component and implement the IBackgroundTask::Run method.
    • I have written a short article on how to do it in C++
    • Yes, C#, JavaScript, C++, and Visual Basic are all supported languages for background tasks.  This sample is currently being updated for beta and samples for all four languages will be available.
1 - 10 of 15 Items