65.9K
CodeProject is changing. Read more.
Home

Run only one instance from you program

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.83/5 (6 votes)

Sep 24, 2010

CPOL
viewsIcon

6524

Use this function in Program.Main()private static bool IsAlreadyRunning(){ //Find name of current process string currentProcessName = Process.GetCurrentProcess().ProcessName; //Find the name of all processes having current process name Process[]...

Use this function in Program.Main()
private static bool IsAlreadyRunning()
{
    //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;
    else
       return false;
}