Game Development Reference
In-Depth Information
Finally, another approach, though a simplified version of the WMI implementa-
tion, is to use the Process object from the System.Diagnostics namespace. While the
WMI version is extremely extensible and robust, the following code using the Process
object is better suited to our needs because it is lightweight.
using System.Diagnostics;
[STAThread]
static void Main()
{
Process process = Process.GetCurrentProcess();
if (Process.GetProcessesByName(process.ProcessName).Count > 1)
{
MessageBox.Show(“There is already an instance of this “ +
“executable running as a process”);
}
else
Application.Run(new MainForm());
}
So far we have discussed a couple of the earlier ways to implement single instance
applications, but with the advent of .NET 2.0, a new integrated approach was pro-
vided that takes care of all the ugly details behind the scenes.
Journey to the Dark Side
Every CLR-compliant language for the .NET platform can reproduce identical
functionality by sharing a common set of framework components. This is because
CLR-compliant languages must support the interoperability with other assemblies
that can be written in a variety of managed languages, meaning that an assembly
written in Visual Basic .NET must be accessible from within a C# application with-
out any performance overhead related to data conversion or “thunking.”
Legacy versions of Visual Basic provided a variety of pre-built components that
aided in the development of applications. Visual Basic .NET exposes a similar
library of components that are generally accessed through the property pages of
the project. One component in particular is the ability to restrict an application so
that it may only be launched once, and redirect the command line parameters
from subsequent instances to the initial one. Visual Basic .NET has a checkbox in
the project properties that enables this functionality, but Visual C# .NET does not
provide it at this time.
Search Nedrilad ::




Custom Search