我需要多次运行一个进程。每次我调用一个实现对象的静态方法Process
和ProcessStartInfo
。属性已ProcessStartInfo
修改为返回错误或输出。Parallel.For
是否可以在循环内调用静态方法?我找不到任何与此相关的线程安全文档。
public static void Run(string item1, string item2, string item3, string item4)
{
var ProcInfo = new ProcessStartInfo(Program.exe,(item1+item2+item3+item4));
ProcInfo.CreateNoWindow = true;
ProcInfo.UseShellExecute = false;
ProcInfo.WorkingDirectory = Environment.CurrentDirectory;
ProcInfo.RedirectStandardError = true;
var process = Process.Start(ProcInfo);
process.WaitForExit();
string error = process.StandardError.ReadToEnd();
int exitCode = process.ExitCode;
Console.WriteLine("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
Console.WriteLine("ExitCode: " + exitCode, "ExecuteCommand");
process.Dispose();
}