下面的代码是创建一个多线程的例子,启动程序在for循环中动态创建多条线程可是为啥没有创建成功呢??只显示一个线程在运行showNum方法.... 请各位大大指点,谢谢
private void button1_Click(object sender, EventArgs e)
{
createThread();
}
void createThread()
{
for (int i = 0; i < 30; i++)
{
Thread th = new Thread(new ThreadStart(showNum));
th.IsBackground = true;
th.Start();
//label1.Text = "启动了" + i + "个线程对象!";
}
}
void showNum()
{
DateTime start = DateTime.Now;
for (int i = 0; i < 9999; i++)
{
textBox1.Text = i.ToString();
Thread.Sleep(100);
}
DateTime end = DateTime.Now;
TimeSpan span = end - start;
MessageBox.Show(span.Seconds.ToString());
}