[英]Using async / wait, UI Freezes after setting content
遇到了一些問題,無法理解為什么會出現。 我正在使用.net 4.5 / C#,並且嘗試在異步功能成功后將Content設置為ContentControl。 在程序的那部分中,我想要的主要焦點是在自己的WPF加載動畫(Usercontrol IsLoading)和PDF內容(Usercontrol PDFDokument)之間切換。 PDF已在內部加載並呈現在“ PDFDokument”中,並且已經可以很好地工作了。 如果需要更多信息,歡迎提出任何要求。 如您所知,我會說我仍處於起步階段。 (三年中的第一年:))
public ucPDFDocument PDFDokument = new ucPDFDocument();
public ucLoading IsLoading = new ucLoading();
protected async void lstSuchergebnis_DoubleClickItem(object sender, MouseButtonEventArgs e)
{
var tempAkte = ((ListViewItem)sender).Content as Akten;
tbctrlResultPanel.SelectedIndex = 1;
PDFDokument.IsDataChangeAllowed(false);
contSwapControls.Content = IsLoading;
await PDF(tempAkte);
contSwapControls.Content = PDFDokument; **<-- after executing this line, the ui freezes**
}
private Task PDF(Akten paramAkte)
{
Akten _tempAkte = paramAkte;
return Task.Run(() => { PDFDokument.LoadPDFDokument(_tempAkte.akt_ID, ref _DaKsManger); });
}
我嘗試了使用異步加載的不同方法,但是沒有任何方法可以解決該問題。
希望有人知道如何解決這個問題:)
非常感謝!!!
唯一異步的是您正在等待的PDF(...)
。 設置內容不是以異步方式執行。 您設置的內容發生在UI線程上。 (這是唯一的方法,因為您正在修改UI,這只能在創建UI的線程上發生)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.