I have a console app that I need to manage multiple processes. By manage i mean that if one process exits that i want to start it up again. So basically my main process will run all the time and watch to see if process 1 or 2 exits and if so to start them again.
With following code the program just exits right away with 0 errors.
static void Main() {
Task.Run(() => Process1());
Task.Run(() => Process2());
}
private static void Process1() {
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "a process 1 file path";
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
try {
using (Process exeProcess = Process.Start(startInfo)) {
exeProcess.WaitForExit();
}
Process1();
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
private static void Process2() {
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "a process2 file path";
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
try {
using (Process exeProcess = Process.Start(startInfo)) {
exeProcess.WaitForExit();
}
Process2();
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}