请教WPF/C#中关于线程安全的数据类型,怎么可以多线程访问的问题
1个回答
2016-07-27
展开全部
protected void UpdateUI()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(10);
this.Dispatcher.BeginInvoke(new Action(
() =>
{
this.textBox1.Text += DateTime.Now.ToString();
this.textBox1.Text += "\r\n";
this.progressBar1.Value = i + 1;
}));
}
}
Thread thread = new Thread(UpdateUI);
thread.Start();
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(10);
this.Dispatcher.BeginInvoke(new Action(
() =>
{
this.textBox1.Text += DateTime.Now.ToString();
this.textBox1.Text += "\r\n";
this.progressBar1.Value = i + 1;
}));
}
}
Thread thread = new Thread(UpdateUI);
thread.Start();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询