Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
I have a list of proxies then i open list of urls in each one then close chrome after next proxy .
after chrome closed there is win32 exception.

What I have tried:

if (List_IPs_Ports.Count >0)
{
if (ListUrls.Count() > 0)
{
Process BrowserProcess = new Process();
ProcessStartInfo psiObj = new ProcessStartInfo("chrome");

foreach (string proxy in List_IPs_Ports)
{
reg.SetValue("ProxyEnable", 1);
reg.SetValue("ProxyServer", proxy);
BrowserProcess.StartInfo = psiObj;
BrowserProcess.Start();
foreach (string url in ListUrls)
{
Process.Start(url);
Thread.Sleep(time);
}
Process[] processNames = Process.GetProcessesByName("chrome");
processNames.First().Kill();

/* foreach (Process item in processNames)
{
if (processNames.Length > 1)

item.Kill();
}*/
}

reg.SetValue("ProxyEnable", 0);
}
}
Posted
Updated 16-Dec-17 4:26am

1 solution

You are enumerating the processes by name and try to kill them all. If there is a process not started by your application, killing will fail if your application does not have the required privileges (e.g. a manually started chrome instance).

Then you can ignore the exception (just catch it).

But you should think about a different implementation because your application would also kill chrome instances started by the same user as your application. Such an implementation might store the IDs of the started processes and use them to kill the processes.
 
Share this answer
 
Comments
BasmaSH 23-Jul-16 12:24pm    
You are right.
So I used namespace Selenium that have it's owne browser.
http://jayeshsorathia.blogspot.com.eg/2014/09/selenium-c-how-to-open-chrome-broswer-in-selenium-webdriver-using-asp-net.html
then i kill it .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900