I have the following lines of code:
Process aProcess = Process.Start("ieexplorer", aDummyHTMLFilePath);
//I do nothing in between
This runs smooth if there are NO other IE windows open.
But if there is a window open, I get a
aProcess.Kill(); saying :
Cannot process request because the process has exited.
Also, I notice that in this case,
aProcess.HasExited is true right after line 1 in the code above.
How can I smoothly close IE, even if there are other IE windows open?
When you start a new instance of Internet Explorer like you do it will try to see if Internet Explorer is already running. If that is true the URL is opened in the already running instance and the new instance exits immediately. This means that when you try to kill the process you started it has already exited voluntarily. However, you will see a new browser window or tab on your screen but that is being hosted by the existing Internet Explorer process.
I didnt get the same issues as you
I found that the following worked if the process was still running or not
Process p = Process.Start("notepad.exe", ""); Thread.Sleep(5000); if (!p.HasExited) p.Kill();
It only complained IF the window had been closed. Hence the check