110,535
社区成员
发帖
与我相关
我的任务
分享
private bool StartThreads()
{
bool IfTimesEnd = false;
IfRunOver = false;
Thread newThread = new Thread(new ThreadStart(ThreadProc));
newThread.Start();
while (!IfRunOver)
{
IfTimesEnd = newThread.IsAlive;
System.Windows.Forms.Application.DoEvents();
if (!IfTimesEnd || IfRunOver)
{
newThread.Interrupt();
newThread.Abort();
IfTimesEnd = false;
break;
}
}
return !IfTimesEnd;
}
而主线程中的相关代码为:
while (true)
{
IfTimesEnd = StartThreads();
IfThreadOver = IfTimesEnd && true;
System.Windows.Forms.Application.DoEvents();
if (IfRunOver && IfThreadOver)
{
pt.Stop();
str = "用时:" + pt.Duration + " 秒\n";
richTextBox1.ScrollToCaret();
richTextBox1.AppendText(str);
richTextBox1.Update();
break;
}
}