Created
June 25, 2014 19:52
-
-
Save cleytonferrari/4bbad56e039594cf3b03 to your computer and use it in GitHub Desktop.
Abre um processo e fica monitorando, caso o processo seja finalizado ele volta a reabrir!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
namespace MonitorCPU | |
{ | |
class Program | |
{ | |
public static void Main() | |
{ | |
Monitorar(); | |
Console.ReadLine(); | |
} | |
private static void Monitorar() | |
{ | |
const string nomeDoProcesso = "notepad.exe"; //NOME DO PROCESSO | |
var psi = new ProcessStartInfo | |
{ | |
FileName = nomeDoProcesso | |
}; | |
var p = new Process | |
{ | |
StartInfo = psi, EnableRaisingEvents = true | |
}; | |
p.Exited += AbrirNovamente; | |
p.Start(); | |
} | |
private static void AbrirNovamente(object o, EventArgs e) | |
{ | |
Console.WriteLine("Processo finalizado! Reiniciando o processo!!! {0}",DateTime.Now.ToString()); | |
Monitorar(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment