Background task sample

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

 
 
 
 
 
(22)
39,604 times
Add to favorites
4/2/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • first launch app to register backgroud task.
    2 Posts | Last post April 08, 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 :
      
            <Extensions>
              <Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTaskWorker.LocationBackgroundTask">
                <BackgroundTasks>
                  <Task Type="timer" />
                </BackgroundTasks>
              </Extension>
            </Extensions>
      
      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?
      
      Thanks
    • 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++ http://progmar.wordpress.com/2012/01/30/background-task-sample-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.
  • does not fire the TimeTrigger
    3 Posts | Last post January 30, 2012
    • I just replace the SystemTrigger with TimeTrigger, but the task was not fired: I have add the Timer in the manifest.
      
                       BackgroundTaskBuilder myTaskBuilder = new BackgroundTaskBuilder();
      
                      //
                      // Create a new InternetAvailable trigger. 
                      //
                      //var myTrigger = new SystemTrigger(SystemTriggerType.InternetAvailable, false);
                      TimeTrigger myTrigger = new 
                          TimeTrigger(15, false);
      
                      //
                      // Associate the InternetAvailable trigger with the background task builder.
                      //
                      myTaskBuilder.SetTrigger(myTrigger);
      
                      System.Diagnostics.Debug.WriteLine(DateTime.Now + "Stat ...");
      
                      //
                      // Specify the background task to run when the trigger fires.
                      //
                      myTaskBuilder.TaskEntryPoint = SampleBackgroundTaskEntryPoint;
      
                      //
                      // Name the background task.
                      //
                      myTaskBuilder.Name = SampleBackgroundTaskName;
      
                      //
                      // Register the background task. 
                      //
                      var myTask = myTaskBuilder.Register();
      
                      //
                      // Associate progress and completed event handlers with the new background task.
                      //
                      myTask.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
                      myTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
                      System.Diagnostics.Debug.WriteLine(myTask.Name + "  "+ myTask.TaskId);
                      UpdateSampleBackgroundTaskUIState(true);
    • In order for timer tasks to fire the application must currently be on the lock-screen.  This sample is currently in the process of being updated for BETA and the updated sample has more information.
    • 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.
  • How to put my app on the lockScreen?
    1 Posts | Last post December 07, 2011
    •     I want to make an App which is like a mail App. So, I want to know how to provide my icon to show on the lockScreen, and how can I update the number which show user there is how many mail is new for him ?
1 - 10 of 13 Items