Game Development Reference
In-Depth Information
MessageBox.Show(“There is already an instance of this executable “ +
“running as a process”);
// Keep the mutex alive until the process terminates
Application.Run(new MainForm());
Another method is to use Windows Management Instrumentation (WMI) to
query the operating system for a listing of active processes filtered by name. Some
developers may favor this approach to the other solutions, so the following code
has been included to show an implementation using WMI. The Companion Web
site has the full source code with additional comments.
public sealed class ProcessCountManager
public static int Query(string applicationName)
return QueryRunningProcessCount(applicationName);
public static int Query(System.Reflection.Assembly assembly)
// Break the full path to the executing assembly into
// a string array of parts
string[] locationParts = assembly.Location.Split(“\\”.ToCharArray());
// Retrieve the application name from the last element
// of the location array
string applicationName = locationParts[locationParts.Length - 1];
// Return the running process count for the specified application name
return QueryRunningProcessCount(applicationName);
public static bool IsRunning(string applicationName)
// Add 1 to account for the application doing the check
return Query(applicationName) > 1;
Search Nedrilad ::

Custom Search