I am using watin for browser automation, and many browser windows get left open, and at the end I am using this to attempt to close them all:
Process[] ieProcesses = Process.GetProcessesByName("iexplore");
foreach (Process ie in ieProcesses)
{
ie.CloseMainWindow();
ie.Close();
ie.Dispose();
}
For some reason close, closemainwindow, and dispose, all will not close my iexplore processes. If I step through this part with the debugger, ieProcesses will have all the processes in it, normally ~10, and it’ll go through the foreach for each one but watching in the task manager, none of them close.
This may have to do with that they are started in hidden windows maybe? but I’m not sure the right way to close them then. Any idea?
Try the
ie.Kill()method:http://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill.aspx