Multiple process launching, monitoring and automatic rebooting

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi everyone,
Im trying to build an application which has the following functions:<br/>
1) Launching multiple applications from a directory.<br/>
2) Watching the processes after theve launched<br/>
3) Rebooting a process, if it crashes.<br/>
<br/>
My directory looks like this:
<pre class="prettyprint Dictionary<string, dynamic> TestApps = new Dictionary<string, dynamic>
{
{"Calc", new {fileName = "calc.exe", args = "0"}},
{"cmd", new {fileName = "cmd.exe", args = "0"}},
};[/code]
<br/>
And to launch the applications im using this code:
<pre class="prettyprint public void StartServer()
{
Thread thread = new Thread(() => InitServers());
thread.Start();
}

private void InitServers() {
foreach (KeyValuePair<String, dynamic> server in TestApps)
{
LaunchApplication(server.Value.fileName.ToString());
Thread.Sleep(2000);
}
}

public void LaunchApplication(string File)
{
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = File;
p.StartInfo = psi;
p.EnableRaisingEvents = true;
p.Start();
}[/code]
<br/>
Which works fine. However im not sure wether this is good practice or not?<br/>

What i havnt been able to figure out is how i should monitor the processes after theyve launched, and if they crash i need to reboot them. Ive played around with Process.Exited, but i havnt been able to get it to work properbly with multiple processes,
cause i cant tell which of the processes exited.
Ive been suggested sending a KeepAlive packet, to monitor them, but im not sure how this is done, and how stable it is.
So i was home someone here, could point me in the right direction :-)<br/>

Thank you in advance,<br/>
Daniel


View the full article
 
Back
Top