Вопрос

I am currently using a simple button to open a webpage.

void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
}

What I want to do is get it to open 3 pages at once with the one click and I am having a hard time getting it to work. I have tried multiple Process.start lines

void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
System.Diagnostics.Process.Start("http://www.gmail.com");
System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}

and even adding multiple pages into the handler.

void ReportingClick(object sender, EventArgs e)
{ 
System.Diagnostics.Process.Start("http://www.google.ca","http://www.gmail.com","http://www.s    tackoverflow.com")
}

It will only open the last page in the list in both cases. Any ideas?

Это было полезно?

Решение

If IE is open, your code works fine and opens each link in a new tab, if not, I was able to make it work by making the app wait for 1 sec before calling the second page to open:

void ReportingClick(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("http://www.google.ca");
    System.Threading.Thread.Sleep(1000);
    System.Diagnostics.Process.Start("http://www.gmail.com");
    System.Threading.Thread.Sleep(1000);
    System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top