纯粹为了以后参考
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace StartMultiProcess
{
class Program
{
private static int m_finishTaskCount = 0;
static async void StartProcesses(string exePath, string args = "")
{
// object output;
Console.WriteLine("Begin Start Processes");
using (Process p = new Process())
{
p.StartInfo.FileName = exePath;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.RedirectStandardError = false;
p.Start();
p.WaitForExit();
//if (p.ExitCode != 0)
//{
// output = p.StandardError.ReadToEnd();
//}
//else
//{
// output = p.StandardOutput.ReadToEnd();
//}
}
Console.WriteLine("End Start Processes");
// Console.WriteLine(output);
Interlocked.Increment(ref m_finishTaskCount);
}
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
//Task.Run(() => StartProcesses("E:/Workspace/SimplePrintProcess/bin/Debug/net5.0/SimplePrintProcess.exe", "111 xxx"));
//Task.Run(() => StartProcesses("E:/Workspace/SimplePrintProcess/bin/Debug/net5.0/SimplePrintProcess.exe", "222 yyy"));
Task.Run(() => StartProcesses("E:/Workspace/ro/config/Table/Tools/BatTools/BatTool/BatTool.exe"
, "-config:config.txt -bytes -localization -localization.write.command.xlsx -type:all -quick"));
Task.Run(() => StartProcesses("E:/Workspace/ro/config/Table/Tools/BatTools/BatTool/BatTool.exe"
, "-config:config.txt -bytes -localization -localization.write.command.xlsx -type:all -area:1"));
Task.Run(() => StartProcesses("E:/Workspace/ro/config/Table/Tools/BatTools/BatTool/BatTool.exe"
, "-config:config.txt -bytes -localization -localization.write.command.xlsx -type:all -area:3"));
Task.Run(() => StartProcesses("E:/Workspace/ro/config/Table/Tools/BatTools/BatTool/BatTool.exe"
, "-config:config.txt -bytes -localization -localization.write.command.xlsx -type:all -area:4"));
while (true)
{
if (m_finishTaskCount >= 4)
{
break;
}
}
sw.Stop();
Console.WriteLine($"Hello Main Process End, cost time:{sw.ElapsedMilliseconds}");
Console.ReadLine();
}
}
}