そのため、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>
どんな助けでも大歓迎です。このコードで十分な情報が得られない場合は、さらに多くの情報を提供できます。アプリの実行中にすべての機能が動作するため、アプリの他の部分に (既知の) 問題はありません。