【发布时间】:2016-03-03 09:30:37
【问题描述】:
如何更正每个新启动的线程使用新计数器的代码。在您启动新线程的那一刻,旧线程挂起,而不是继续。
感谢您的帮助。
private void button1_Click(object sender, EventArgs e)
{
thread[counter] = new Thread(goThread);
thread[counter].Start();
counter++;
}
private void goThread()
{
kolejka[counter] = new PictureBox();
kolejka[counter].Location = new Point(325, n - 150);
kolejka[counter].Image = threading.Properties.Resources.car;
kolejka[counter].Size = new Size(20, 37);
this.Invoke((MethodInvoker)delegate
{
this.Controls.Add(kolejka[counter]);
});
for (int i = 0; i < 500; i++)
{
this.Invoke((MethodInvoker)delegate
{
kolejka[counter].Location = new Point(kolejka[counter].Location.X, kolejka[counter].Location.Y - 3);
this.Refresh();
});
Thread.Sleep(50);
}
}
【问题讨论】:
-
您好,在您获得帮助后,请不要破坏您的帖子。这就像在树下避难后砍倒一棵树。请允许其他未来的用户从知识中获益。回答者会付出很多努力。不要浪费他们宝贵的时间。
标签: c# multithreading counter