Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Run only one instance from you program

Rate me:
Please Sign up or sign in to vote.
4.83/5 (6 votes)
24 Sep 2010CPOL 6.4K   2   1
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;
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Indra Italia s.p.a
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
TychoBarfy18-Apr-13 16:29
TychoBarfy18-Apr-13 16:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.