From 85ce10c69641ed76a03056703e1d668b08a09c30 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 25 Aug 2013 22:43:34 +0000 Subject: [PATCH] In Single Instance Mode - don't show an ObjectDisposedException --- BizHawk.MultiClient/Program.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/BizHawk.MultiClient/Program.cs b/BizHawk.MultiClient/Program.cs index 66094fd74e..6f9d2b8420 100644 --- a/BizHawk.MultiClient/Program.cs +++ b/BizHawk.MultiClient/Program.cs @@ -87,8 +87,14 @@ namespace BizHawk.MultiClient #if WINDOWS if (Global.Config.SingleInstanceMode) { - SingleInstanceController controller = new SingleInstanceController(args); - controller.Run(args); + try + { + new SingleInstanceController(args).Run(args); + } + catch (ObjectDisposedException ex) + { + /*Eat it, MainForm disposed itself and Run attempts to dispose of itself. Eventually we would want to figure out a way to prevent that, but in the meantime it is harmless, so just eat the error*/ + } } else { @@ -193,30 +199,27 @@ namespace BizHawk.MultiClient #if WINDOWS public class SingleInstanceController : WindowsFormsApplicationBase { - MainForm mf; readonly string[] cmdArgs; public SingleInstanceController(string[] args) { cmdArgs = args; IsSingleInstance = true; StartupNextInstance += this_StartupNextInstance; - } void this_StartupNextInstance(object sender, StartupNextInstanceEventArgs e) { - mf.LoadRom(e.CommandLine[0]); + (MainForm as MainForm).LoadRom(e.CommandLine[0]); } protected override void OnCreateMainForm() { - MainForm = new RamWatch(); - - mf = new MainForm(cmdArgs); - MainForm = mf; - mf.Show(); - mf.ProgramRunLoop(); - } + MainForm = new MainForm(cmdArgs); + var title = MainForm.Text; + MainForm.Show(); + MainForm.Text = title; + (MainForm as MainForm).ProgramRunLoop(); + } } public static void DisplayDirect3DError()