2014-11-05 60 views
0

类似后立即离开到 Process.Start("IEXPLORE.EXE") immediately fires the Exited event after launch.. why?C#程序启动firefox.exe火灾推出

的-nomerge选项似乎并不为Firefox浏览器。

更新时间:

这里有一个控制台应用程序

static bool exitCalled = false; 
static string baseUrl = <some url to display in the browser>; 

var process = new Process 
{ 
    StartInfo = new ProcessStartInfo 
    { 
     FileName = "Firefox.exe" 
     Arguments = " -url " + baseUrl + " -no-remote -P MyProfile " 
    } 
} 

process.EnableRaisingEvents = true; 
process.Exited += new EventHandler(delegate(Object o, EventArgs e) 
{ 
    // process has exited 
    Console.WriteLine("Exited event called"); 
    Console.ReadLine(); 
    exitCalled = true; 
} 

process.Start(); 
while (!exitCalled) 
{ 
    Thread.Sleep(100); 
} 

运行这段代码中的C#代码的预览显示消息浏览器调用之前“之称已退出事件”。

+0

你尝试'/ nomerge'而不是'-nomerge'?显然,Firefox可能不支持nomerge,但只是想检查。 – 2014-11-05 16:51:40

+0

/nomerge也不起作用。 – BKN 2014-11-05 16:54:43

+0

它看起来像我在调用process.Start _inside_对象初始值设定项。这可能导致问题吗?而不是那个循环,你应该使用'process.WaitForExit()' – 2014-11-05 19:15:44

回答

1

这是因为-nomerge是IE特定的程序参数,对于Firefox,您需要使用-no-remote。您还需要传递-P程序参数,因为不建议使用默认配置文件启动另一个Firefox进程。请参考以下链接上开始新的Firefox实例:

http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile

+0

-no-remote也没有工作。用示例代码更新了我的问题。谢谢。 – BKN 2014-11-05 18:26:22

+0

@BKN我做了一些研究,如果没有很多努力来编写firefox的工作方式,你的努力将无法工作。没有-P选项的Firefox将加载默认配置文件,这意味着您不能使用默认配置文件创建2个实例。但是,只有任何配置文件名称都不能使用-P,因为一旦配置文件管理器退出后它将显示配置文件管理器,则会发生退出事件。从外观上看,它可以做到,但就像我说过的那样,它需要一点点代码。 – 2014-11-05 19:31:02

+0

谢谢@ T.V。我的意图是使用NancyFx/OWIN创建一个自我托管的应用程序,并允许用户选择他们喜欢的浏览器。 – BKN 2014-11-06 14:16:10