Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

c# - Process.Start("IEXPLORE.EXE") immediately fires the Exited event after launch.. why?

i have a strange problem with IE8 installed in xp. i was trying to launch IE using an System.Diagnostics.Process.Start method in c#. And i have a requirement to trap the exited event of the IE and do some operation. But i ended up in a rather strange problem where the IE immediately fires the exited event after launch.

this is the sample code

     Process objProcess = Process.Start("IEXPLORE.EXE", "http://google.com");

     if (objProcess != null)
    {
        objProcess.EnableRaisingEvents = true;
        objProcess.Exited += new EventHandler(myProcess_Exited);        
    }

    public  static void myProcess_Exited(object sender, System.EventArgs e)
    {
        MessageBox.Show("You exited");
    }

But the above code perfectly works when laucnching different process (ex:notepad) and it fires the exit event when i close the exe.

this only gives problem launching IE 8. Can someone clarify me what is the problem??

UPDATE

Most friends replied my post and saying why you can't just use an URL? why stick with IE?

here the reason

the ultimate aim of the app is to launch an URL from the windows application and will hide an exe when working on the IE. And show the exe after closing the IE.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most probably is that you have IE already running as a process, so when you try to launch it again as a new process it looks that there are IE running already, tells it that user initiated a new window (so the initial IE will create a "new" window rather than a new one) and exit.

Possible solution: try starting the process with "-nomerge" command line option:

    Process objProcess = Process.Start("IEXPLORE.EXE", "-nomerge http://google.com/");

Interesting observation: objProcess.ExitCode (for IE8 at least) will be equal to 0 if exited passing control to another instance, and 1 if it was actually closed by user.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...