在我的应用程序中有耗时的过程。因此,我尝试在单独的线程中执行该操作。即使我将它分开了,我的主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