Extended execution in UWP

半城伤御伤魂 提交于 2019-12-31 06:25:30

问题


I want to use a background task for my UWP app.

The below code, is my back button click event in windows mobile-

private async void MainPage_BackRequested(object sender, BackRequestedEventArgs e)
{
   var access= await BackgroundExecutionManager.RequestAccessAsync();
    var task = new BackgroundTaskBuilder
    {
        Name="My task",TaskEntryPoint=typeof(backGroundTask.Class1).ToString()
    };
    trigger = new ApplicationTrigger();
    task.SetTrigger(trigger);
    task.Register();
    //var result = await trigger.RequestAsync();
    if (Frame.CanGoBack)
    {
        Frame.GoBack();
        e.Handled = true;
    }
}


public void Run(IBackgroundTaskInstance taskInstance)
{
    _deferral = taskInstance.GetDeferral();
    clearData();
    count1 = 0;
    getDownloadedSongs();

    dispatcherTimer1.Tick += DispatcherTimer1_Tick;
    dispatcherTimer1.Interval = new TimeSpan(0, 0, 3);
    dispatcherTimer1.Start();
    _deferral.Complete();



}
DispatcherTimer dispatcherTimer1 = new DispatcherTimer();

 private async void DispatcherTimer1_Tick(object sender, object e)
{

    try
    {
          clearData();

    }
    catch (Exception ex)
    {
    }
}

what is the way to do it with Extended execution in uwp ..specifically for windows mobile 10


回答1:


ExtendedExecution will allow you to keep running and finish your task before you get suspended. Please take a look at the official sample for ExtendedExecution




回答2:


Extended Execution has been in talks for quite a long now. You can definitely continue the app execution even when it is minimized. I don't have a working sample yet but you can get some insight by looking at the link here



来源:https://stackoverflow.com/questions/44551853/extended-execution-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!