title: Is it possible to get own process name?
body: <p>I want to replace cMyProcessName (in my example) programatic, i dont want to use a sting constant !</p>
  
  <p>This is the code:</p>
  
  <pre><code>private const string cMyProcessName = "MyProcessName";
  
  if (GetProcessCount(cMyProcessName) &gt; 1)
  {
      System.Threading.Thread.Sleep(2000); //Give it some time (if just restarted)
      //**************************************************************//
      if (GetProcessCount(cMyProcessName) &gt; 1)
      {
          MessageBox.Show("MyProcessName is already running. Exiting.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
      }
      //**************************************************************//
  }
  
  public static int GetProcessCount(string processName)
  {
      Process[] ps = Process.GetProcessesByName(processName);
  
      return ps.Length;
  }
  </code></pre>