locked
Why does MaintenanceTrigger not work? How do I get it work?

    Question

  • Hello, I'm currently using MaintenanceTrigger in my background task,According to the white page, I programed on a pc to trigger the background task every 15m with javascript , I manifest the task type "timer", but it does not seem to work. However, when i use TimeTrigger, it works fine. Who can tell me why and how to use the MaintenanceTrigger. Thanks a lot!
    Monday, April 9, 2012 12:21 PM

Answers

  • Hello, Genrge:

    Here are the steps to repeat my experiment:

    1. Get the Background Task sample from here: Background Task Sample  (Download the version marked "C#, JavaScript (62.8KB)"
    2. Unzip the sample and run the solution in Visual Studio
    3. The solution will have 2 projects: BackgroundTask and BackgroundTaskSample.  View the /js/program.js in theBackgroundTaskSample.
    4. Comment out or replace Line 122 as I instructed in my previous post above.  This will make Scenario 1 trigger with a MaintenanceTrigger instead of a TimeZoneChange.
    5. Run the program (F5).
    6. Select Scenario 1, "Simple background task in C#" in the dropdown.
    7. Click "Register"
    8. Wait and watch for a change on the line marked "Progress".  When the background task fires, this line will start a count up to 100%.

    In this scenario, the main program in JavaScript but the background task is the C# program SimpleBackGroundTask.cs that is in the other project.  The main program (program.js) has registered a background task progress handler and can display the results of the background task.  The foreground task should be running so that you can see the results of the example, but, of course, is not required in general for background tasks to run.

    If you look at the manifest, you will see there are 3 background task declarations.  The second one is used for this scenario.  Note that the entry point is the name of the C# program and that the executable is "BackgroundTaskHost.exe" which is a requirement for using a MaintenanceTrigger.

    • Marked as answer by Genrge Friday, April 13, 2012 1:38 AM
    Thursday, April 12, 2012 11:57 AM

All replies

  • The task could take up to 30 minutes.

    When you trigger the MaintenanceTrigger with a freshness time of 15 minutes, the background task is scheduled to be run and that could be 15 minutes after that trigger (total 30 minutes).  Using a TimeTrigger you have to be a lock screen app.  Lock screen apps have a higher QOS and would be run before the non lockscreen apps.  Finally you are allocated only a certain amount of processor time so could it be you are exceedign that?

    Also the MaintenanceTrigger will only be triggered if you are on AC power.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, April 9, 2012 7:11 PM
    Moderator
  • The maintenance trigger does not require the app to be on the lock screen and executes on the 15 minute boundaries of each hour (according to the white paper).  But what is the correct manifest or other secret sauce?

    Is it possible that background tasks that are launched by the maintenance trigger must be written in C#/C++ to meet the requirement of the white paper:

    "Background tasks triggered by MaintenanceTrigger must be hosted in BackgroundTaskHost.exe; that is, they can only run in BackgroundTaskHost.exe and not in the app executable. "

    I think JavaScript background tasks might not be run in BackgroundTaskHost.exe.

    • Edited by jrboddie Monday, April 9, 2012 11:38 PM
    Monday, April 9, 2012 11:07 PM
  • To jpsanders:

         Hi, thank a lot for answering, so far as my test, it does not work long after minutes. I think my pc is on AC power, would you give me a demo, thank you again.

    To jrboddie:

        MSDN has a sample written in javascript which does not seem to work. if you might give me a demo written in C#/C++, that would be fine.

    Tuesday, April 10, 2012 12:23 PM
  • I think I got it to work with a JavaScript main and C# background.exe.  In the Background Task sample for JavaScript I replaced line 122 in program.js:

    new Windows.ApplicationModel.Background.SystemTrigger(Windows.ApplicationModel.Background.SystemTriggerType.timeZoneChange, false),

    with this:

    new Windows.ApplicationModel.Background.MaintenanceTrigger(15, false),

    I ran the program in VS, selected the first scenario "Simple Background Task in C#", Registered the task and waited.

    I actually did some yard work and when I came back in the house (about an hour later) the Progress indicator was 100%.  

    I didn't change the manifest which still indicated System Event and Timer for this scenario, so I don't know if they are important in this case.

    Edit: Restarted the app a few minutes (>15) ago and just looked up to see the Progress at 100%.  So I presume, it triggered again.

    Edit again: I saw it trigger this time at xx:57.  The white paper implied that maintenance triggers are synced with the system clock and occur on the 15 minute divisions of real time rather than from the point the trigger was registered.






    • Edited by jrboddie Tuesday, April 10, 2012 4:03 PM
    Tuesday, April 10, 2012 3:31 PM
  • Hi, jrboddie, i'm exited to get these data, it might work. I want to know where might the trigger be used other than pushNotification. I used it to write a file, it does not work, cpu usage might tell us that it worked, the result can't convince me.Thank you again.

    Wednesday, April 11, 2012 1:35 AM
  • And another question, i make it the same way like you, but my cpu usage does not seem to grow. My pc works on Windows 8250, does your computer work on the same system. 
    Wednesday, April 11, 2012 1:55 AM
  • My desktop says "Build 8250".  I don't understand your "cpu usage does not seem to grow."

    Wednesday, April 11, 2012 2:25 PM
  • Hi, jrboddie, i'm sorry if i have mixed "Progress indicator" with "cpu usage of process", but now i'm puzzled with what "Progress indicator" is, you mean the "Progress indicator" of the background task, right?

    If it worked, could you tell me more details, like what arguments you set, what task you triggered? Grateful for your sparing no efforts.

    Thursday, April 12, 2012 1:18 AM
  • Hello, Genrge:

    Here are the steps to repeat my experiment:

    1. Get the Background Task sample from here: Background Task Sample  (Download the version marked "C#, JavaScript (62.8KB)"
    2. Unzip the sample and run the solution in Visual Studio
    3. The solution will have 2 projects: BackgroundTask and BackgroundTaskSample.  View the /js/program.js in theBackgroundTaskSample.
    4. Comment out or replace Line 122 as I instructed in my previous post above.  This will make Scenario 1 trigger with a MaintenanceTrigger instead of a TimeZoneChange.
    5. Run the program (F5).
    6. Select Scenario 1, "Simple background task in C#" in the dropdown.
    7. Click "Register"
    8. Wait and watch for a change on the line marked "Progress".  When the background task fires, this line will start a count up to 100%.

    In this scenario, the main program in JavaScript but the background task is the C# program SimpleBackGroundTask.cs that is in the other project.  The main program (program.js) has registered a background task progress handler and can display the results of the background task.  The foreground task should be running so that you can see the results of the example, but, of course, is not required in general for background tasks to run.

    If you look at the manifest, you will see there are 3 background task declarations.  The second one is used for this scenario.  Note that the entry point is the name of the C# program and that the executable is "BackgroundTaskHost.exe" which is a requirement for using a MaintenanceTrigger.

    • Marked as answer by Genrge Friday, April 13, 2012 1:38 AM
    Thursday, April 12, 2012 11:57 AM
  • Well, it did work in c#, I never tried this type of trigger. Thank you . In javascript, however, it might not work. I will have another try in javascript.

    Friday, April 13, 2012 1:43 AM
  • hi, jpsanders

    When I used the MaintenaceTrigger in javascript,it work.Is there any difference between javascript and C# in background task?

    Wednesday, August 15, 2012 2:50 AM
  • You can create a task in another process in .NET.  Other than that there is technically no difference.


    Jeff Sanders (MSFT)

    • Proposed as answer by feeeeeeeeei Thursday, August 16, 2012 2:15 AM
    Wednesday, August 15, 2012 12:27 PM
    Moderator
  • Thanks,jpsanders

    I got it.

    Thursday, August 16, 2012 2:15 AM