所以我似乎遇到了一些问题,在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>
任何帮助将不胜感激。如果此代码信息不足,我可以提供更多信息。应用程序的其他部分没有(已知)问题,因为所有功能在应用程序运行时都有效。
答案 0 :(得分:0)
您需要让BackroundBuilder
班级实施IBackgroundTask
interface。
答案 1 :(得分:0)
这是一个错字:builder.TaskEntryPoint = "PostPage.xmal";
应该是:builder.TaskEntryPoint = "PostPage.xaml";
?
如果SLaks的回答似乎无法解决问题,我会指出这一点。
我会将其作为评论输入,但我没有足够的代表来做到这一点。
答案 2 :(得分:0)