要实现后台任务,需要实现IBackgroundTask接口

1     public sealed class SimpleTask : IBackgroundTask
2     {
3         public void Run(IBackgroundTaskInstance taskInstance)
4         {
5             // TODO
6         }
7     }

假设需要用到异步方法,则要这么写:

1     public sealed class SimpleAsyncTask : IBackgroundTask
2     {
3         public async void Run(IBackgroundTaskInstance taskInstance)
4         {
5             BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
6             // TODO
7             deferral.Complete();
8         }
9     }

 

相关文章:

  • 2021-10-15
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-03
  • 2021-09-20
  • 2021-10-08
  • 2021-12-28
  • 2021-12-27
相关资源
相似解决方案