在我的應用程序中有耗時的過程。因此,我嘗試在單獨的線程中執行該操作。即使我將它分開了,我的主UI仍然在長時間運行的過程中凍結。但仍然無法弄清楚原因呢?我的代碼中有些東西錯了?用戶界面凍結,甚至過程開始與單獨的線程?
我的事件處理代碼
private void BtnloadClick(object sender, EventArgs e)
{
if (null != cmbSource.SelectedItem)
{
string selectedITem = ((FeedSource) cmbSource.SelectedItem).Url;
if (!string.IsNullOrEmpty(selectedITem))
{
Thread starter = new Thread(() => BindDataUI(selectedITem));
starter.IsBackground = true;
starter.Start();
}
}
private void BindDataUI(string url)
{
if (feedGridView1.InvokeRequired)
{
BeginInvoke(new Action(() => BindDataGrid(url)));
}
else
BindDataGrid(ss);
}
private void BindDataGrid(string selectedItem)
{
for (int i = 0; i < 10; i++)
{
//Time consuming Process
}
}
您需要將BindDataGrid拆分爲與UI相關而非與UI相關的內容。 – 2012-03-19 11:55:32
感謝您的意見 – Renushi 2012-03-19 11:58:39