0

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.

Álvaro García
  • 16,711
  • 26
  • 88
  • 167
  • 3
    `p.CloseMainWindow();`? https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.closemainwindow?view=net-6.0 – UnholySheep Jan 11 '22 at 21:40

0 Answers0