Game Development Reference
In-Depth Information
Upon closer inspection of a single instance VB.NET application with a disassem-
bler, Microsoft.VisualBasic.dll is referenced by the runtime. This assembly exposes
the WindowsFormsApplicationBase class that exists in the Microsoft.VisualBasic.
ApplicationServices namespace. This class provides a mechanism to restrict an
application so that it may only be launched once, and this mechanism supports the
redirection of command line parameters to itself. Microsoft.VisualBasic.dll is a
common framework component, and it is accessible from any managed language
because it is merely a library of compiled MSIL byte code.
The Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase class
will be used to implement the solution, as presented in the next section.
The Solution
The following namespaces are used by the solution, and the only other namespace
below worth mentioning is System.Collections.ObjectModel . This namespace pro-
vides a generic ReadOnlyCollection that wraps a data type into a strongly typed,
read-only list.
using System;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using Microsoft.VisualBasic.ApplicationServices;
The solution in this chapter will require a way to send a notification to the main
application instance when another instance attempts to launch. The following
class describes the event arguments that will be passed with the notification. It
merely stores a reference to the main form of the application and a collection of
string parameters that were passed by the command line.
internal class SingleInstanceEventArgs : EventArgs
{
private ReadOnlyCollection<string> commandLine;
private Form mainForm;
internal ReadOnlyCollection<string> CommandLine
{
get { return commandLine; }
}
internal Form MainForm
Search Nedrilad ::




Custom Search