使用Lumia 920,看起来即使在调试模式下也不会调用我的OnInvoke。调用从ScheduledTaskAgent继承的ScheduledAgent的构造函数。这意味着WMAppManifest.xml中的设置是正确的。
<Tasks>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
<ExtendedTask Name="BackgroundTask">
<BackgroundServiceAgent Specifier="ScheduledTaskAgent" Name="PeriodicAgent" Source="ScheduledPlaybackAgent" Type="ScheduledPlaybackAgent.ScheduledAgent" />
</ExtendedTask>
</Tasks>
然后我几乎从示例代码中复制了一遍:
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)
{
}
}
我在启动前台应用程序后故意切换到主屏幕,并尽可能多地等待。我的ScheduledAgent :: OnInvoke
仍然没有输出或断点谢谢!
答案 0 :(得分:4)
您是否在ScheduledAgent.cs中定义了#define DEBUG_AGENT并在OnInvoke中包含以下代码?
#if(DEBUG_AGENT)
ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30));
System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name);
#endif