在我的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);
}
我無法弄清楚如何解決這個問題。