Game Development Reference
In-Depth Information
}
private static void StartupNextInstanceEventHandler(object sender,
StartupNextInstanceEventArgs e)
{
if (SingleInstanceEvent != null)
{
SingleInstanceEvent(applicationBase,
new SingleInstanceEventArgs(e.CommandLine, applicationBase.MainForm));
}
}
}
The following code shows how a WinForms application is generally launched.
[STAThread]
static void Main()
{
// The old way to launch the application
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
The following code shows the new way a WinForms application will be launched
using the single instance component.
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
SingleInstanceApplication.Run(new MainForm(), StartupNextInstanceEventHandler);
}
You should have noticed the StartupNextInstanceEventHandler . This parameter is a
delegate that will be fired when a subsequent instance is launched, and the main
instance should be notified and given the command line parameters. The follow-
ing code shows how to implement this delegate, activate the main form of the
application, and pass command line parameters to the form.
private static void StartupNextInstanceEventHandler(object sender,
SingleInstanceEventArgs e)
{
// Restore the window if it is currently minimized
if (e.MainForm.WindowState == FormWindowState.Minimized)
Search Nedrilad ::




Custom Search