C# 多个同时 System.Diagnostics.Process
我有一个 C# 类 MyCommand,它使用 backgroundWorker 和线程池运行。 MyCommand 使用 Process 类执行命令行可执行文件。 MyCommand 的实例每个都在自己的线程中,以串行方式而不是并行方式运行。我只是想知道 MyCommand 中 Process.Start() 的执行是否会阻塞其他线程。
Process pProcess = new Process();
pProcess.StartInfo.FileName = "decrypt.exe";
pProcess.StartInfo.Arguments = "list of args" ;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
pProcess.WaitForExit();
I have a C# class, MyCommand, that is run using a backgroundWorker and thread pool. MyCommand executes a command line executable using the Process class. The instances of MyCommand, each in their own thread, are running in a serial fashion instead of parallel. I'm just wondering if the execution of Process.Start() in MyCommand is blocking the other threads.
Process pProcess = new Process();
pProcess.StartInfo.FileName = "decrypt.exe";
pProcess.StartInfo.Arguments = "list of args" ;
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
pProcess.WaitForExit();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
No Process.Start 不会阻塞。但是您正在启动的应用程序可能会。例如,如果它使用互斥体来确保一次只有一个实例运行。
No Process.Start doesn't block. However the application you're starting might. For example if it used a mutex to make sure only one instance of was running at one time.
答案很简单:不,启动进程不会阻塞其他线程。
The answer is simple: no, starting a process doesn't block other threads.