Skip to main content
added 817 characters in body
Source Link
Mohammad
  • 589
  • 2
  • 9
  • 25

I need to run a process multiple times. Each time I call an static method that implement an objects from Process and ProcessInfoProcessStartInfo. The ProcessInfoProcessStartInfo 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(); } 

I need to run a process multiple times. Each time I call an static method that implement an objects from Process and ProcessInfo. The ProcessInfo 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.

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(); } 
Source Link
Mohammad
  • 589
  • 2
  • 9
  • 25

Thread safety multiple process

I need to run a process multiple times. Each time I call an static method that implement an objects from Process and ProcessInfo. The ProcessInfo 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.