running another process

I run an exe using

Process.Start("myexe.exe");

how can i check if the process is running so i dont run it twice

Thank You



Answer this question

running another process

  • shakalama

    there ar a couple of ways.

  • get a list of processes by name and see if the collection is returned...

    Process

  • [] theProcesses = Process.GetProcessesByName("processName");

    if (theProcesses.Length > 1)

    {

       //more than 1 process is running

    }

     

    you could also get the process by ID which is returned by the Process.Start() method, returns a process object.

  • could check to see if the process has exited via the HasExited Property

    Process theProc = Process.Start("filename.exe");

    ...

    ...

    if (!theProc.HasExited)

    {

       //....

    }

     

    I believe its the first one you are after, hopefully



  • running another process