我正在使用 C# 中的 System.DIagnostics.Process 创建一个进程
我创建了一个从该类CCProcess
继承的Process
类
问题是 ErrorDataRecieved OR OutputDataReceived 没有被解雇..这是我的代码
public CCProcess(string executablePath, string[] parameters, CCProcessInfo processInfo)
{
this.ProcessInfo = processInfo;
this.OutputMessages = new List<ProcessOutputMessage>();
this.ProcessId = Guid.NewGuid().ToString();
base.EnableRaisingEvents = true;
this.StartInfo = new ProcessStartInfo(executablePath)
{
Arguments = string.Join(" ", parameters.Select(s => string.Format("\"{0}\"", s))),
CreateNoWindow = true,
ErrorDialog = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
StandardErrorEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
this.ErrorDataReceived += (sender, e) =>
{
this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Error });
if (this.ErrorData_Recieved != null&&!string.IsNullOrEmpty(e.Data))
{
this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
this.ErrorData_Recieved(e.Data);
}
};
this.OutputDataReceived += (sender, e) =>
{
this.OutputMessages.Add(new ProcessOutputMessage() { Message = e.Data, Type = OutputType.Output });
if (OutputData_Recieved != null && !string.IsNullOrEmpty(e.Data))
{
this.ProcessInfo.LastResponseFromProcess = DateTime.Now;
OutputData_Recieved(e.Data);
}
};
}
我究竟做错了什么?
提供的代码是类的构造函数CCProcess