Archives

Archives / 2004 / May
  • Checking if an application is already running

    Many Windows Forms applications only allow a single instance to run at a time. The following snippet is a clean way to check if your process is already running:

    static public bool AlreadyRunning()
    {
        string processName = Process.GetCurrentProcess().ProcessName;
        Process[] processes = Process.GetProcessesByName(processName);
        return (processes.Length > 1);
    }