我想使用 c# 使用多个线程执行应用程序我试过如下正常方法应用程序执行怎么样? public static void OneThread() { DateTime startTime = DateTime.Now; Thread t11 = new Thread(() => { for (int i = 0; i <= 5; i++) { var proc = new Process(); proc.StartInfo.FileName = @"C:\Users\consoleapp.exe"; proc.StartInfo.Arguments = "-v -s -a"; proc.Start(); proc.WaitForExit(); var exitCode = proc.ExitCode; proc.Close(); } }); t11.Start(); t11.Join(); Console.WriteLine("execution 1 thread 5 times in {0} seconds", (DateTime.Now - startTime).TotalSeconds); }
1 回答
动漫人物
TA贡献1815条经验 获得超10个赞
我不知道我是否正确理解了这个问题。此代码有执行相同方法的 n 个线程
int n = 5;
for (int i = 0; i < n; i++)
{
Thread t = new Thread(MethodToExecute);
t.Start();
}
public void MethodToExecute()
{
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "pathToConsoleApp.exe";
process.Start();
process.WaitForExit();// Waits here for the process to exit.
}
- 1 回答
- 0 关注
- 243 浏览
添加回答
举报
0/150
提交
取消