因此,我似乎在windows商店应用程序中触发后台任务时遇到了一些问题;我遵循了白皮书《教程》,并查看了来自微软的示例代码,我的代码的所有迭代似乎都失败了。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>任何帮助都将不胜感激。如果这段代码不能提供足够的信息,我可以提供更多。应用程序的其他部分没有(已知的)问题,因为所有功能都在应用程序运行时工作。
发布于 2013-06-19 02:51:35
TaskEntryPoint应该是实现IBackgroundTask的类的名称(包括命名空间)。例如。"BackgroundTasks.MyBackgroundTask“。
这也应该添加到您的清单文件中。打开Package.appxmanifest,转到声明选项卡,添加后台任务声明,并以相同的名称填写“入口点”字段(例如"BackgroundTasks.MyBackgroundTask")。
此外,您的任务需要位于单独的Windows Runtime组件项目中,并且该项目中的每个类都必须是public和sealed。
Here是一个快速教程。
可以在here上找到一个扩展版本。
发布于 2012-12-28 06:33:13
您需要让您的BackroundBuilder类实现IBackgroundTask interface。
发布于 2012-12-28 06:50:22
这是一个拼写错误吗:builder.TaskEntryPoint = "PostPage.xmal";应该是:builder.TaskEntryPoint = "PostPage.xaml";吗?如果SLaks的答案似乎不能解决问题,我会指出这一点。
我想输入这作为一个评论,但我没有足够的代表来这样做。
https://stackoverflow.com/questions/14059197
复制相似问题