private void btnQuery_Click(object sender, EventArgs e)
{
long index =0;//传值
Thread t = new Thread(new ParameterizedThreadStart(Exe));
t.Start(index);
}
private void Exe(object index)
{
//耗时操作
var task = Task.Factory.StartNew(() =>
{
while (true)
{
try
{
//判断条件符合后跳出循环
break;
}
catch (Exception ex)
{
this.Invoke((EventHandler)delegate
{
MessageBox.Show(ex.Message);
});
break;
}
}
});
task.Wait();//等待task执行结束
this.Invoke((EventHandler)delegate
{
//更新ui
});
}
异步更新ui
最新推荐文章于 2024-07-11 10:49:40 发布