banner



What Background Tasks Should I Cancel

  • Remove From My Forums

 locked

Background chore cancel notification

  • Question

  • How-do-you-do all,

          I take annals a background task, but it can run,I received a lot of errors in Effect Viewer: XXXXTask  did not consummate in response to a abolish notification.What'south the reason? The post-obit is the code.

    namespace photostudio {     //     // A background task e'er implements the IBackgroundTask interface.     //     public sealed class TileUpdateTask : IBackgroundTask     {         public const string TileUpdateTaskEntryPoint = "photostudio.TileUpdateTask";         public const string TileUpdateTaskName = "TileUpdateTask";         //         // The Run method is the entry signal of a background chore.         //         public void Run(IBackgroundTaskInstance taskInstance)         {             Debug.WriteLine("Background " + taskInstance.Task.Name + " Starting...");         }                         public static BackgroundTaskRegistration RegisterTileUpdateTask()         {             foreach (var cur in BackgroundTaskRegistration.AllTasks)             {                 if (cur.Value.Proper noun == TileUpdateTaskName)                 {                     cur.Value.Unregister(truthful);                     //return null;                 }             }             var builder = new BackgroundTaskBuilder();             architect.Name = TileUpdateTaskName;             builder.TaskEntryPoint = TileUpdateTaskEntryPoint;             IBackgroundTrigger trigger = new SystemTrigger(SystemTriggerType.ServicingComplete, false);             builder.SetTrigger(trigger);             /*             if (condition != nada)             {                 architect.AddCondition(condition);             }*/             BackgroundTaskRegistration task = builder.Register();                          //             // Remove previous completion condition from local settings.             //            // var settings = ApplicationData.Electric current.LocalSettings;             //settings.Values.Remove("TileUpdateTask");                           return task;         }             }

Answers

  • Hello,

    Do you lot the Groundwork chore definition in the different projection? If not, try separating information technology from the main project. You can debug the groundwork chore - http://msdn.microsoft.com/en-usa/library/windows/apps/jj542415.aspx

    Background tasks can be canceled by the organization in sure conditions. To receive cancellation notifications, the app's background tasks should register a cancellation handler by using the IBackgroundTaskInstance. When the arrangement cancels a groundwork task, information technology provides a reason in the BackgroundTaskCancellationReason parameter of the BackgroundTaskCanceledEventHandler.If the background task does non respond to the cancellation notification and does not return from its groundwork job within five seconds, the app is terminated. To ensure a graceful leave and ensure consistent app state, apps are encouraged to annals a cancellation handler and save state and exit the background chore in response to a counterfoil asking.

    -Sagar

    • Marked as answer by Wednesday, September 12, 2012 7:xiii AM
    • Marked every bit answer past Aaron Xue Wednesday, September 12, 2012 vii:fourteen AM
  • I saw the code in the first post above and seems like you lot are registering the servicing task in the same class where you ascertain the class inheriting from IBackgroundTask - which is not recommended. The code for registering tasks should be in the principal app. The other projection where you ascertain and implement the classes with IBackgroundTask should only have the "Run()" forth-with progress and cancelled event handlers for the task.

    Besides, at that place seems to be a discrepancy in TaskEntryPoint assignment. The TaskEntryPoint  should be proper name of the class that implements the "IBackgroundTask" interface.

    Also, check if there are any previous Servicing tasks running as they are registered during previous sessions.

    -Sagar

    • Marked equally answer by Aaron Xue Wednesday, September 12, 2012 vii:fifteen AM

What Background Tasks Should I Cancel,

Source: https://social.msdn.microsoft.com/Forums/en-US/77c6806c-92d8-4205-8096-689bc128e04b/background-task-cancel-notification?forum=winappswithcsharp

Posted by: leeyoutive.blogspot.com

0 Response to "What Background Tasks Should I Cancel"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel