2017-06-14 47 views
0

我想为我的UWP应用程序使用后台任务。在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扩展执行做..specifically移动视窗10

回答

2

ExtendedExecution会的方式允许您保持运行并在您被暂停之前完成您的任务。请看看official sample的ExtendedExecution

+0

没有人为我的案件工作..我已经写在应用程序暂停事件的ExtendedExecution代码..但它不工作.. –

+0

是否有可能最小化Windows Mobile中的应用程序当我点击返回按钮 –

+0

你是什么意思的“最小化”?在手机上,等同于最小化的是将应用程序放在导航的backstack上,当你点击后退按钮时,应该会自动为你发生。 –