2016-04-29 34 views
0

在我的Windows應用商店中,我有一個await函數,有時需要花費幾分鐘的時間才能完成(將會諮詢某些其他線程的性能)。同時,如果用戶關注應用程序,則會崩潰。當我查看事件日誌時,出現以下錯誤:Windows UWP,在異步調用期間掛起時應用程序崩潰

App was terminated because it took too long to suspend.

我在應用程序中使用Prism。我已經處理Application.Current.Suspending,用下面的代碼(它總是叫):

protected void OnApplicationSuspending(object sender, SuspendingEventArgs e) 
    { 
     var defferal = e.SuspendingOperation.GetDeferral(); 
     if (sessionStateService.SessionState.ContainsKey("plotId")) 
     { 
      sessionStateService.SessionState.Remove("plotId"); 
     } 

     sessionStateService.SessionState.Add("plotId", Plot.Id); 

     if (sessionStateService.SessionState.ContainsKey("Page")) 
     { 
      sessionStateService.SessionState.Remove("Page"); 
     } 

     sessionStateService.SessionState.Add("Page", "OperationRecording"); 

     defferal.Complete(); 
    } 

我也重寫OnNavigatingFrom功能,用於保存導航參數(它確實沒有別的)。

public override void OnNavigatingFrom(NavigatingFromEventArgs e, Dictionary<string, object> viewModelState, bool suspending) 
    { 
     if (viewModelState.ContainsKey("plotId")) 
     { 
      viewModelState.Remove("plotId"); 
     } 

     viewModelState.Add("plotId", Plot.Id); 

     base.OnNavigatingFrom(e, viewModelState, suspending); 
    } 

我無法弄清楚如何解決這個問題。

回答

3

如果你暫停你的應用程序,你應該在5秒內完成它。
Application.Suspending

Saving data prior to suspension is useful because the Suspending event handler has only 5 seconds to complete its operation.

所以,更好的保存大量數據,由於應用程序工作的。
您還可以閱讀Guidelines for app suspend and resume

在UWP您還可以暫停時以較大擴展執行

幫助
相關問題