关于线程同步的问题,急
private int a;
Thread t ;
private void button1_Click(object sender, System.EventArgs e)
{
start();
MessageBox.Show(a.ToString());
}
private void count()
{
for(int i=0;i <1000;i++)
{
a=i;
}
}
private void start()
{
t = new Thread(new ThreadStart(count));
t.Start();
}
为什么MessageBox.Show(a.ToString());中a的结果是0而不是999呢?如何做才能使a的值为999?
------解决方案--------------------private void button1_Click(object sender, System.EventArgs e)
{
start();
t.Join();
MessageBox.Show(a.ToString());
}