所以我似乎在 Windows 商店应用程序中触发后台任务时遇到了一些问题;我已经按照白皮书教程进行了操作,并查看了 Microsoft 的示例代码,并且我的代码的所有迭代似乎都失败了。Visual Studio 没有给我任何错误后台任务只是没有触发,任务的目的是在有互联网连接时每 70 分钟触发一次。
下面代码的范围是它在自己的名为 Tasks 的项目中,并且清单(不是针对此项目,而是解决方案中的主项目)已正确填充,以便在此类中找到后台任务
class BackroundBuilder
{
public BackroundBuilder()
{
this.RegisterTimeTriggerBackgroundTask();
}
//this is the code that registers my backround task to run a trigger
//was added for testing.
private bool RegisterTimeTriggerBackgroundTask()
{
BackgroundTaskBuilder builder = new BackgroundTaskBuilder();
builder.Name = "Background task test";
builder.TaskEntryPoint = "PostPage.xmal";
// Run every 70 minutes if the device has internet connectivity
IBackgroundTrigger trigger = new TimeTrigger(70, false);
builder.SetTrigger(trigger);
IBackgroundCondition condition = new
SystemCondition(SystemConditionType.InternetAvailable);
//this is the trigger it's set to fire when internet becomes available
IBackgroundTrigger Itrigger = new
SystemTrigger(SystemTriggerType.InternetAvailable,true);
builder.SetTrigger(Itrigger);
builder.AddCondition(condition);
IBackgroundTaskRegistration task = builder.Register();
return true;
}
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral _deferral = taskInstance.GetDeferral();
//WindowsBlogReader.FeedDataSource updateAll = new WindowsBlogReader.FeedDataSource();
//direct input for the test string is declared below but the updateAll declaration
// above is the one that will be used once the test works
WindowsBlogReader.LiveTileTimeUpdate updateAll = new WindowsBlogReader.LiveTileTimeUpdae();
//this is the test to see if the background task will fire
//await was in front of the below statement but im injecting that String into a method
//that is not setup for async the method being used once this works is an async
updateAll.update("Background task fired");
//this update method adds a String too the list of Sting that's the live tile cycles though
_deferral.Complete();
}
}
这是清单 xml 代码
<Extension Category="windows.backgroundTasks" EntryPoint="Tasks.BackroundBuilder">
<BackgroundTasks>
<Task Type="systemEvent" />
<Task Type="timer" />
</BackgroundTasks>
</Extension>
任何帮助,将不胜感激。如果此代码信息不足,我可以提供更多信息。应用程序的其他部分没有(已知)问题,因为所有功能都在应用程序运行时工作。