Which usage is best for adding TileTask to ScheduledActionService for WP?

47 views Asked by At

There are some usages for adding TileTask to ScheduledActionService but I didn't understand which one is best usage. For example;

private void StartPeriodicAgent(string taskName)
    {
        tilePeriodicTask = ScheduledActionService.Find(taskName) as PeriodicTask;
        if (tilePeriodicTask != null)
        {
            RemoveAgent(taskName);
        }
        tilePeriodicTask = new PeriodicTask(taskName);
        tilePeriodicTask.Description = "App Tile Agent";
        try
        {
            ScheduledActionService.Add(tilePeriodicTask);

            // If debugging is enabled, use LaunchForTest to launch the agent in one minute.
 #if(DEBUG)
            ScheduledActionService.LaunchForTest(taskName, TimeSpan.FromSeconds(30));
 #endif
        }
        catch (InvalidOperationException)
        {
            //MessageBox.Show(ex.ToString());
        }
        catch (SchedulerServiceException)
        {

        }
    }

This method is remove existing tileTask and add again everytime. Is it true? Have I remove and add it again every usage? Or Shouldn't I remove-add it if it exists?

Thanks.

1

There are 1 answers

0
Adam Benoit On

In all applications I have used LiveTiles in, I used the example provided my Microsoft for working with tiles. In that sample, they remove the existing task agent before recreating it, just like your code above. I would do that.

I realize there are cases where the samples Microsoft provides are completely against accepted best practices, but in this case, I believe that the sample is correct (and therefore, your code).

I hope this helps put your mind at ease.