Windows phone: using periodic agent

1

I have an Windows Phone markeplace app. Users reports that app sometimes crashes at Windows Phone 8. Here is my data from windows phone dev center report:

Problem funciton:

Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr

Exception type

system.reflection.targetinvocationexception

Stack trace:

Frame    Image                 Function                                                                  Offset        
0        microsoft_phone_ni    Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr               0x0000019a    
1        microsoft_phone_ni    Microsoft.Phone.Scheduler.SystemNotificationInterop.CreateNotification    0x0000002e    
2        microsoft_phone_ni    Microsoft.Phone.Scheduler.ScheduledActionService.Add                      0x00000056    
3        myapp_ni              Myapp.MainPage..ctor                                                      0x000000b0

Problem can be with background agent. I have used these tutorial.

My code:

public MainPage()
    {
        InitializeComponent();

        /* Periodic agents*/
            // A unique name for your task. It is used to  
            // locate it in from the service. 
            var taskName = "MyTask";

            // If the task exists 
            var oldTask = ScheduledActionService.Find(taskName) as PeriodicTask;
            if (oldTask != null)
            {
                ScheduledActionService.Remove(taskName);
            }

            // Create the Task 
            PeriodicTask task = new PeriodicTask(taskName);

            // Description is required 
            task.Description = "This saves some data to Isolated Storage";

            // Add it to the service to execute 
            ScheduledActionService.Add(task);

          /* Testing my agent*/
         //   ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromMilliseconds(1500));
           /* Testing my agent*/

        /* Periodic agents */
...

I readed ScheduledActionService.Find throws ArgumentException, but didn't got idea behind it

c#
windows-phone
background-agents
periodic-task
asked on Stack Overflow Dec 14, 2013 by Karloss • edited May 23, 2017 by Community

1 Answer

0

You must put your periodic agent code in App.xaml.cs inside method on Application_Closing

answered on Stack Overflow Aug 17, 2014 by Raditya Kurnianto

User contributions licensed under CC BY-SA 3.0