2014-11-06 61 views
2

我做了一個後臺任務,使其在NetworkStateChange上偵聽,並且工作正常。從BackgroundTask執行程序

我試圖通過Windows.System.Launcher.LaunchUriAsync推出一個計劃,但我在嘗試時訪問被拒絕例外:

下面是任務來源:

namespace Tasks 
{ 
    public sealed class Upload : IBackgroundTask 
    { 
     BackgroundTaskDeferral _deferral = null; 
     private bool wifiConnected = false; 

     public bool WiFiConnected 
     { 
      get 
      { 
       return wifiConnected; 
      } 
      set 
      { 
       if (value == wifiConnected) 
        return; 

       wifiConnected = value; 
      } 
     } 


     public void Run(IBackgroundTaskInstance taskInstance) 
     { 

      var InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); 
      WiFiConnected = InternetConnectionProfile != null; 

      if (!WiFiConnected) 
      { 
       LaunchFlexCheck(); 
       return; 
      } 


      _deferral = taskInstance.GetDeferral(); 
      _deferral.Complete(); 
     } 

     private async void LaunchFlexCheck() 
     { 
      Debug.WriteLine("BEFORE LaunchFlexCheck()"); 
      bool result = false; 
      try 
      { 
       result = Windows.System.Launcher.LaunchUriAsync(new System.Uri("myapp:MainPage")).GetResults(); 
      } 
      catch (Exception e) 
      { 
       result = false; 
       Debug.WriteLine("LaunchFlexCheck exception:" + e.Message); 
      } 

      Debug.WriteLine("LaunchFlexCheck succes:" + (result ? "true" : "false")); 
      Debug.WriteLine("AFTER LaunchFlexCheck()"); 
     } 

    } 
} 

是更多鈔票是這樣做的?

回答

3

啓動從後臺任務的應用意味着用戶會在自己在做什麼,中間被打斷,推出他沒有請求的應用。這與Windows Phone的設計指南完全相反,用戶必須始終保持控制權。因此,我相信這是不可能的。