2014-11-05 33 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