Windows phone: using periodic agent

446 views Asked by At

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

1

There are 1 answers

0
Raditya Kurnianto On

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