Game Development Reference
In-Depth Information
get { return mainForm; }
internal SingleInstanceEventArgs(ReadOnlyCollection<string> commandLine,
Form mainForm)
this.commandLine = commandLine;
this.mainForm = mainForm;
An important goal of this solution is to transition easily from the standard launch-
ing approach for an application to our new single instance version. This goal war-
ranted the design of a static class that exposes a simple Run method, much like the
Application class. The Run method takes in a reference to the main form of the
application and a delegate to the method that will handle subsequent instance
notifications. The WindowsFormsApplicationBase has a StartupNextInstance event
that is fired when another instance is launched. This solution handles this event
behind the scenes and redirects the event arguments with additional information
to the SingleInstanceEvent delegate.
internal class SingleInstanceApplication : WindowsFormsApplicationBase
private SingleInstanceApplication()
base.IsSingleInstance = true;
private static EventHandler<SingleInstanceEventArgs> SingleInstanceEvent;
private static SingleInstanceApplication applicationBase;
internal static void Run(Form form,
EventHandler<SingleInstanceEventArgs> handler)
SingleInstanceEvent += handler;
applicationBase = new SingleInstanceApplication();
applicationBase.MainForm = form;
applicationBase.StartupNextInstance += StartupNextInstanceEventHandler;
Search Nedrilad ::

Custom Search