I would like if there is another way to close an application instead of using kill, because I am trying to open an close firefox in a loop and after some loops, I get the error that firefox was close in an expected way.
So I am wondering if there is another way to say close the process instead of kill.
My code is this:
while (true)
{
try
{
CerrarProcesosFirefox();
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = @"C:\Program Files\Mozilla Firefox\firefox.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
await Task.Delay(10000);
myProcess.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
void CerrarProcesosFirefox()
{
Process[] ps = Process.GetProcessesByName("firefox");
foreach (Process p in ps)
{
p.Kill();
}
}
Thanks.