My Photo
Location: Bangalore, India

Tips to Reduce Abdominal Fat!

Monday, July 17, 2006

Previous instance of an application in C#

How to check whether a previous instance of an application is already running in C#?

It is possible with C# to look for previous instances of an application. Here is a method.

private static bool IsPrevInstance()
//Find name of current process
string currentProcessName = Process.GetCurrentProcess ().ProcessName;
//Find the name of all processes having current process name
Process[] processesNamesCollection = Process.GetProcessesByName(currentProcessName);
//Check whether more than one process is running
if (processesNamesCollection.Length > 1)
return true;
return false;

Note: Process class is available in System.Diagnostics name space


Post a Comment

<< Home