benshepherd icon

[C#] Check if process is running

benshepherd | PRO | 12/15/12 11:00:43 PM UTC | 0 ⭐ | 309 👁️ | Never ⏰ | []
C# |

710 B

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
 
namespace ScrSnap
{
    class ProcessCheck
    {
        public bool isAlreadyRunning()
        {
            bool running = false;
 
            string toMatch = Application.ProductName;
            Process[] procsRunning = Process.GetProcesses();
            int matchesFound = 0;
 
 
            foreach (Process p in procsRunning)
            {
                if (toMatch == p.ProcessName.ToString())
                    matchesFound++;
            }
 
            if (matchesFound > 1) running = true;
 
            return running;
        }
    }
}

Comments