2017-01-20 29 views
0

我已經對它進行了GOOGLE搜索,但沒有發現任何內容。 該控制檯顯示:程序「[2952] backgroundTaskHost.exe」已退出,並顯示代碼1(0x1)

The program "[2952] backgroundTaskHost.exe" has exited with the code 1 (0x1) 

的MainProject得到了參考Backgroundtask。任務在等待fileIO讀取器時退出。

StorageFile sampleFile = await storageFolder.GetFileAsync("Klasse.txt"); 
Stufe = await FileIO.ReadTextAsync(sampleFile); 

之前,我已經叫另一FileIO專注閱讀器,但任務沒有退出

StorageFile sampleFile = await storageFolder.GetFileAsync("Facher.txt"); 
Fach = await FileIO.ReadTextAsync(sampleFile); 

總而言之:

namespace BackgroundTask 
{ 
    public sealed class BackgroundTask : IBackgroundTask 
    { 
     string Stufe = ""; 
     string Fach = ""; 

     BackgroundTaskDeferral _deferral; 
     public async void Run(IBackgroundTaskInstance taskInstance) 
     { 
      _deferral = taskInstance.GetDeferral(); 
      StorageFolder storageFolder = ApplicationData.Current.LocalFolder; 

      //GetFächer 
      try 
      { 
       StorageFile sampleFile = await storageFolder.GetFileAsync("Facher.txt"); 
       Fach = await FileIO.ReadTextAsync(sampleFile); 
      } 
      catch (Exception e) { } 

      //GetStufe 
      try 
      { 
       StorageFile sampleFile = await storageFolder.GetFileAsync("Klasse.txt"); 
       Stufe = await FileIO.ReadTextAsync(sampleFile); 
      } 
      catch (Exception e) { Debug.WriteLine(e); } 
      _deferral.Complete(); 

      [...] 
     } 
} 
+2

爲什麼你得到多個延期?我認爲你應該在* Run *開始之後得到一個,並在最後完成。如果您在任務中間調用complete,可能OS會將其視爲已完成並釋放資源。你嘗試過嗎? – Romasz

+0

哦,斯里。這只是一個嘗試修復錯誤 –

+0

通過把它放在最後。之前是在等待聲明之後,但現在在最後。謝謝 –

回答

0

我不得不把完整的標籤在很結束。現在它可以工作

相關問題