Process.Start("IEXPLORE.EXE") 在启动后立即触发 Exited 事件..为什么? [英] Process.Start("IEXPLORE.EXE") immediately fires the Exited event after launch.. why?

查看:26
本文介绍了Process.Start("IEXPLORE.EXE") 在启动后立即触发 Exited 事件..为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 xp 中安装 IE8 时遇到一个奇怪的问题.我试图在 c# 中使用 System.Diagnostics.Process.Start 方法启动 IE.我需要捕获 IE 的退出事件并执行一些操作.但我最终遇到了一个相当奇怪的问题,即 IE 在启动后立即触发退出事件.

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.

这是示例代码

     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");
    }

但是上面的代码在启动不同的进程(例如:记事本)时完美地工作,当我关闭 exe 时它会触发退出事件.

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

这只会在启动 IE 8 时出现问题.有人可以澄清我是什么问题吗?

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

更新

大多数朋友回复我的帖子并说为什么不能只使用 URL?为什么坚持使用IE?

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

原因在这里

该应用程序的最终目的是从 Windows 应用程序启动一个 URL,并在 IE 上工作时隐藏一个 exe.并在关闭IE后显示exe.

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.

谢谢

推荐答案

很可能是因为您已经将 IE 作为进程运行,因此当您尝试将其作为新进程再次启动时,它看起来已经有 IE 正在运行, 告诉它用户启动了一个新窗口(因此初始 IE 将创建一个新"窗口而不是一个新窗口)并退出.

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.

可能的解决方案:尝试使用-nomerge"命令行选项启动进程:

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

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

有趣的观察:如果退出将控制权传递给另一个实例,objProcess.ExitCode(至少对于 IE8)将等于 0,并且1 如果它实际上是被用户关闭的.

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.

这篇关于Process.Start("IEXPLORE.EXE") 在启动后立即触发 Exited 事件..为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆