title: How can I check if my program is already running?
body: <p>I tried to do it this way:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Windows.Forms;
  using System.Diagnostics;
  using DannyGeneral;
  
  namespace mws
  {
      static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          static void Main()
          {
              try
              {
                  if (IsApplicationAlreadyRunning() == true)
                  {
                      MessageBox.Show("The application is already running");
                  }
                  else
                  {
                      Application.EnableVisualStyles();
                      Application.SetCompatibleTextRenderingDefault(false);
                      Application.Run(new Form1());
                  }
              }
              catch (Exception err)
              {
                  Logger.Write("error " + err.ToString());
              }
          }
          static bool IsApplicationAlreadyRunning()
          {
              string proc = Process.GetCurrentProcess().ProcessName;
              Process[] processes = Process.GetProcessesByName(proc);
              if (processes.Length &gt; 1)
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
      }
  }
  </code></pre>
  
  <p>But I'm getting some problems.</p>
  
  <p>First, when I'm loading my project in Visual Studio and then running my program it's detecting the vshost.exe file of my project for example: My project.vshost</p>
  
  <p>And I want that it will detect if my program is running only when I'm running the program only if it find the .exe for example: My project.exe not the vshost.</p>