Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP8: Any idea why OnInvoke not called in derived ScheduledTaskAgent

Using Lumia 920, it looks like my OnInvoke is never called even in Debug mode. The Constructor of ScheduledAgent that is inherited from ScheduledTaskAgent is called. Which means that the setup in WMAppManifest.xml is correct.

<Tasks>
  <DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
  <ExtendedTask Name="BackgroundTask">
    <BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="PeriodicAgent" Source="ScheduledPlaybackAgent" Type="ScheduledPlaybackAgent.ScheduledAgent" />
  </ExtendedTask>
</Tasks>

Then I pretty much copied from sample code:

    private void StartPeriodicAgent()
    {
        // Obtain a reference to the period task, if one exists
        periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;

        if (periodicTask != null)
        {
            RemoveAgent(periodicTaskName);
        }

        periodicTask = new PeriodicTask(periodicTaskName);

        periodicTask.Description = "This demonstrates a periodic task.";

        try
        {
            ScheduledActionService.Add(periodicTask);
        }
        catch (InvalidOperationException exception)
        {
        }
        catch (SchedulerServiceException)
        {
        }
    }

I purposely switch to Home screen after foreground app is started and waited as much as I can. Still no output or breakpoint from my ScheduledAgent::OnInvoke

Thanks!

like image 344
thsieh Avatar asked Jan 30 '26 04:01

thsieh


1 Answers

Have you defined #define DEBUG_AGENT in ScheduledAgent.cs and included the following code in OnInvoke?

        #if(DEBUG_AGENT)
            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30));
            System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name);
        #endif
like image 92
airbai Avatar answered Feb 02 '26 06:02

airbai