私の質問は、deferral.complete()
メソッドが正確に何をするか、このメソッドがイベントを呼び出すか、またはクラスtask.Compledet
からメソッドを呼び出す方法があるかということです???? Programm を実行すると、BackgroundTaskSyncer から Run メソッドを実行しますが、他のクラスでは何も実行しませんか??BackgroundTaskSyncer
BackgroundSyncer
namespace NotificationTask
{
public sealed class BackgroundTaskSyncer : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
deferral.Complete();
}
}
}
namespace Services
{
public static class BackgroundSync
{
private static async Task RegisterBackgroundTask()
{
try
{
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
if (status == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity || status == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity)
{
bool isRegistered = BackgroundTaskRegistration.AllTasks.Any(x => x.Value.Name == "Notification task");
if (!isRegistered)
{
BackgroundTaskBuilder builder = new BackgroundTaskBuilder
{
Name = "Notification task",
TaskEntryPoint =
"NotificationTask.BackgroundTaskSyncer"
};
builder.SetTrigger(new TimeTrigger(15, false));
builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
BackgroundTaskRegistration task = builder.Register();
task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
task.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("The access has already been granted");
}
}
private static void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
{
ToTheBackGroundWork();
}