要实现后台任务,需要实现IBackgroundTask接口
public sealed class SimpleTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
// TODO
}
}
假设需要用到异步方法,则要这么写:
public sealed class SimpleAsyncTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
// TODO
deferral.Complete();
}
}