我的代码如下所示:
static AutoResetEvent wait_till_finish = new AutoResetEvent(false);
...if (File.Exists("try.exe"))
{
Thread quartus_thread = new Thread(() => qar_function(@"\quartus");
quartus_thread.Start();
wait_till_finish.WaitOne();
// ONLY after command mode action was finished, and AutoResetEvent is set, lookfor some file in folder
if (File.Exists("def")) {//do something}
}
后来:
public void qar_function(string abc)
{ //does something...
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/k " + String.Join(" ", args));
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = false;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
// ***** now set AutoResetEvent:
wait_till_finish.set();
我的问题如下:
我在一个方法中有“wait_till_finish.WaitOne()”,在我调用 Qar_Function 方法之后它处于等待状态,所以首先我想调用该方法,然后我想等到该方法执行并完成,然后然后,在 qar_function 方法中,我设置了 AutoReset。
它不工作。
我正在使用调试器,它没有在 WaitOne 等待,它只是继续移动到下一行。
我究竟做错了什么?谢谢。