Thread thread = new Thread(new ThreadStart(delegate
{
for (int i = 0; i < 100; i++)
{
this.Invoke(new MethodInvoker(delegate
{
if (i == 99)
{
this.label1.Visible = false;
this.label1.Refresh();
}
this.label1.Text = i.ToString();
this.label1.Refresh();
}));
}
}));
thread.IsBackground = true;
thread.Start();
{
for (int i = 0; i < 100; i++)
{
this.Invoke(new MethodInvoker(delegate
{
if (i == 99)
{
this.label1.Visible = false;
this.label1.Refresh();
}
this.label1.Text = i.ToString();
this.label1.Refresh();
}));
}
}));
thread.IsBackground = true;
thread.Start();
本文探讨了在程序中使用线程进行并发操作,特别是如何在主线程中更新UI控件的过程。通过创建一个后台线程,实现循环计数并根据特定条件更新标签控件的显示状态。
830

被折叠的 条评论
为什么被折叠?



