Hello every one.
I\'m faced with a weird problem. My application has a simple method that in case IE enters a state were it gets unresponsive this m
It is a quirk of Internet Explorer, it starts multiple processes for one session. Killing one of them can cause all of them to exit. You probably see the "process has exited" exception. Do it like this instead:
foreach (var ie in Process.GetProcessesByName("iexplore")) {
try {
ie.Kill();
}
catch {}
}
you shouldn't use "foreach" to kill it, and between two kill, you need delay for the process to be killed completely
Did you wrap your code in a try/catch block to see if an exception was thrown? If not, try
try
{
foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())
{
if (exe.ProcessName.StartsWith("iexplore"))
exe.Kill();
}
}
catch (Win32Exception e)
{
Console.WriteLine("The process is terminating or could not be terminated.");
}
catch (InvalidOperationException e)
{
Console.Writeline("The process has already exited.");
}
catch (Exception e) // some other exception
{
Console.WriteLine("{0} Exception caught.", e);
}
Given that you say you always possess administrative privileges when you attempt to call this method, the following would explain why you have intermittent issues:
System.Diagnostics.Process.Kill:
If the call to the
Kill
method is made while the process is currently terminating, aWin32Exception
is thrown for Access Denied.
If you've quickly hit 'delete' + 'OK' twice, on an entry in Process-Explorer, you'll know what I'm talking about.