class ProcessRestarter
{
private string prog;
private Process handle;
public ProcessRestarter(string program)
{
this.prog = program;
this.handle = new Process();
}
public void Start()
{
Process[] list = Process.GetProcesses();
bool isRunning = false;
foreach (Process p in list)
{
if (string.Compare(p.ProcessName, this.prog, true) == 0)
isRunning = true;
}
if (!isRunning)
{
try
{
this.Restart();
}
catch (Exception e)
{
throw e;
}
}
Thread.Sleep(5000);
Start();
}
private void Restart()
{
this.handle.StartInfo.FileName = this.prog + ".exe";
this.handle.Start();
}
public void Close()
{
Process[] List = Process.GetProcesses();
foreach (Process p in List)
{
if (string.Compare(p.ProcessName, this.prog, true) == 0)
{
p.Kill();
}
}
}