I need to run a process multiple times. Each time I call an static method that implement an objects from Process and ProcessStartInfo. The ProcessStartInfo properties has modified to return errors or outputs. Is it possible to call the static method inside Parallel.For loop? I couldn't find any document about thread safety related to this.
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(); }
ProcessInfoclass are you talking about? There's no such thing inSystem.Diagnostics. Look at the documentation for your class. (For example, msdn.microsoft.com/en-us/library/…). At the bottom under "Thread Safety", it will often say "Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe."