在UWP中扩展执行

问题描述 投票:0回答:2

我想为我的UWP应用程序使用后台任务。

下面的代码,是我在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)
    {
    }
}

在uwp中进行扩展执行的方法是什么?特别适用于Windows Mobile 10

c# uwp windows-10-mobile
2个回答
2
投票

ExtendedExecution将允许您在被暂停之前继续运行并完成任务。请查看official sample的ExtendedExecution


0
投票

延长执行已经谈了很长时间了。即使最小化,您也可以继续执行应用程序。我还没有工作样本,但你可以通过查看here链接获得一些见解

© www.soinside.com 2019 - 2024. All rights reserved.