public static Process RunningInstance()  
{  
     Process current = Process.GetCurrentProcess(); 
     Process[] processes = Process.GetProcessesByName (current.ProcessName); 
      //Loop through the running processes in with the same name 
 
      foreach (Process process in processes) 
       {  
          //Ignore the current process 
            if (process.Id != current.Id) 
           { 
                //Make sure that the process is running from the exe file. 
                 if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName) 
                 { 
                     //Return the other process instance. 
                     return process; 
                 } 
            } 
       } 
       //No other instance was found, return null. 
       return null; 
 }

解决方案 »

  1.   

    http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=E2A17727-765F-4346-8446-5D130622CB54
      

  2.   

    你把Windows API的 CreateMutex 函数引用进来,就可以实现了。
      

  3.   

    [STAThread]
    static void Main() 
    {
    bool runOne; gM1 = new Mutex(true,"MyNotifyDemo");

    runOne=gM1.WaitOne(10,true); if (runOne==false)  //已经有一个实例在运行
    {
    MessageBox.Show("图标已经添加!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);

    return;
    }
    Application.Run(new Form1());

    gM1.ReleaseMutex( );
    }