我已经使用Application触发器在UWP中为后台任务创建了一个应用程序 . 当我使用按钮手动触发事件时,它正在工作 .
我想使用Application触发器在App最小化中调用后台任务事件 . 可能吗?
我使用以下代码通过按钮单击触发后台任务:
public MainPage()
{
this.InitializeComponent();
this.Button_Click();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var taskRegistered = false;
var exampleTaskName = "ExampleBackgroundtask";
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == exampleTaskName)
{
taskRegistered = true;
break;
}
}
if (!taskRegistered)
{
var builder = new BackgroundTaskBuilder();
builder.Name = exampleTaskName;
builder.TaskEntryPoint = "Background.ExampleBackgroundtask";
builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false));
BackgroundTaskRegistration task = builder.Register();
task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
}
}