Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 任务列表流程don';在其执行后不得终止_C#_Mono - Fatal编程技术网

C# 任务列表流程don';在其执行后不得终止

C# 任务列表流程don';在其执行后不得终止,c#,mono,C#,Mono,我正在运行以下代码段: _taskListProcess = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cm

我正在运行以下代码段:

_taskListProcess = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C tasklist /FO CSV /NH";
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
_taskListProcess.StartInfo = startInfo;
_taskListProcess.EnableRaisingEvents = true;
_taskListProcess.Exited += new EventHandler(HandleTaskListProcessTerminated);
_taskListProcess.Start();
我的问题是任务列表进程永远不会终止。我看到它挂在窗口任务管理器中。因此,我的函数HandleTaskListProcessTerminated从未被调用


我正在开发使用单声道的Unity

由于您设置了
RedirectStandardOutput=true,启动的进程将填充StandardOutput缓冲区。
尝试从
StandardOutput
读取,直到您用尽所有内容:

_taskListProcess.Start();
while (!_taskListProcess.StandardOutput.EndOfStream)
{
    Console.WriteLine(_taskListProcess .StandardOutput.ReadLine());
}

由于您正在重定向输出,因此缓冲区将满。试着用这里提到的方法来解决这个问题。