日期:2014-05-17 浏览次数:20739 次
private void btnStart_Click(object sender, EventArgs e)
{
Init();//此方法耗时较长
this.btnStart.Enabled = false;
while (true)
{
Thread newThread = new Thread(new ThreadStart(doSomeThing));
//设置为单元线程
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
Application.DoEvents();
Thread.Sleep(20000);
}
}
private void doSomeThing()
{
StartImage();//此方法耗时较长
Invoke(new myDelegate(StartImage));
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.Invoke(new MethodInvoker(delegate()
{
//更新UI,提示正在执行后台操作
this.lable1.Text = "正在计算...";
}));
//长时间处理的代码