使用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仍然没有输出或断点
谢谢!
最佳答案
您是否在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