Frage

I'm using this code:

Process p = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.UseShellExecute = true;
si.FileName = Url;
p = Process.Start(si);
p.WaitForExit();

To open the "Url" in the default browser. I want to wait for the user to close that browser and then execute the code further. But after opening the Url in IE (my default browser), it throws an Object reference not set to an instance of object and highlights

p.WaitForExit();

What is the problem? I just want to wait until it finishes. Thanks for any advice.

War es hilfreich?

Lösung

The ProcessStartInfo.FileName gets or sets the application or document to start. What I have done is passed the application path in the FileName so when Process.Start creates it looks for Arguments and creates an instance in your case it does not

Process p = new Process();
ProcessStartInfo si = new ProcessStartInfo();
p.StartInfo = si;
si.UseShellExecute = true;
si.FileName = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe";
si.Arguments = "http://www.stackoverflow.com";
p.Start();
p.WaitForExit();

Andere Tipps

Process.Start(new ProcessStartInfo()
            {
                UseShellExecute = true,
                FileName = "http://google.com",                
            }).WaitForExit();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top