How to prevent two Processes running the Same Application

  1. using System;  
  2.  using System.Collections.Generic;  
  3.  using System.Linq;  
  4.  using System.Windows.Forms;  
  5.  using System.Threading;  
  6.    
  7. namespace MutexClassExample  
  8.  {  
  9.      static class Program  
  10.      {  
  11.          static Mutex m;  
  12.          /// <summary>  
  13.          /// </summary>  
  14.          [STAThread]  
  15.          static void Main()  
  16.          {  
  17.              bool first = false;  
  18.              m = new Mutex(true, Application.ProductName.ToString(), out first);  
  19.              if ((first))  
  20.              {  
  21.                  Application.EnableVisualStyles();  
  22.                  Application.SetCompatibleTextRenderingDefault(false);  
  23.                  Application.Run(new Form1());  
  24.                  m.ReleaseMutex();  
  25.              }  
  26.              else  
  27.              {  
  28.                MessageBox.Show("Application" + " " + Application.ProductName.ToString() + " "  +"already running");  
  29.              }  
  30.          }  
  31.      }  
  32.  }