UI冻结3-10秒,同时更新UI线程中的数据我想在不冻结的情况下更新UI线程中的数据。c#WPF UI在UI线程中更新数据时挂起
代码:
Task t = Task.Factory.StartNew(() =>
{
// Get data from Server
GetData(true);
});
内Getdata()
//Converst JSON to DataSet Object:- "tempDataSet"
Task task = Task.Factory.StartNew(() =>
{
RetriveData(tempDataSet, firstTime);
}, CancellationToken.None, TaskCreationOptions.None, MainFrame.Current);
内RetriveData
DataTable response = tempDataSet.Tables["response"];
DataTable conversations = tempDataSet.Tables["convo"];
foreach (DataRow row in conversations.Rows) // UI Hangs in the method
{
UC_InboxControl control = new UC_InboxControl(row, uC_Inbox);
if (uC_Inbox.mnuUnreadChat.IsChecked == false)
{
inboxControlCollection.Add(control);
}
else
{
inboxUnreadOnlyControlCollection.Add(control);
}
}
什么是更新UI线程UI没有挂起或冻结的最佳方法?
你为什么要在Getdata()里面开始一个新的任务?请发布完整的代码。 – mm8
里面的RetriveData有UI操作,我使用了新的UI任务更新 –
GetData中有哪些UI操作?这没有意义。所有的UI操作都会冻结UI线程。 – mm8