show your code or tryProcess p = ... p.Start(); p.WaitForExit();if you need to terminate the thread,Process p = null; try {} catch (ThreadInterruptedException ex) { if (p != null) p.Kill(); }
楼主看来是对Process和Thread的概念没弄清楚
我的一种思路是: JudgeSystem js = new JudgeSystem(sourceFilename, no); Thread judge = new Thread(new ThreadStart(js.judge)); judge.Start();
我就是想那样做
p.Start();
p.WaitForExit();if you need to terminate the thread,Process p = null;
try
{}
catch (ThreadInterruptedException ex)
{
if (p != null)
p.Kill();
}
JudgeSystem js = new JudgeSystem(sourceFilename, no);
Thread judge = new Thread(new ThreadStart(js.judge));
judge.Start();
Thread.Sleep(6000); //计时
if(judge.IsAlive)
{
judge.Abort(); // 这种做法无法把judge里开出的process停止,而且如果judge没到
//6000就停止了,没法关掉计时线程
}另一种:在js.judge()里面,即用process的地方Process execute = new Process();
//......
execute.Start();
//...... Thread.Sleep(6000);
if(!execute.HasExited)
{
execute.Kill(); //这样可以关掉process execute了,但是每次肯定要延时6000
}我怎么才能改成我想要的功能(见楼顶)呢?
process是进程
thread是线程
是酱紫吗?