C/S应用程序 ,如果该应用程序已经处于运行状态,则提示错误 。。
如果没有运行该程序,则直接运行程序 。。

解决方案 »

  1.   

    http://topic.csdn.net/u/20100716/10/541b7db1-cb85-4e97-8f01-8e214e9e0d8e.html
      

  2.   

    获取系统的所有process(process[] xxx=process.getProcesses())
    判断是否存在同名但是id不一样的进程

       foreach(process Pro in xxx)
         {
              if(xxx.processname="xxxxxxxx"&&xxx.id="xxx")
           {
               xxx
    }}
    })我不记得确切的属性和方法是什么,使用vs 可以自动带出属性和方法这个方法有点笨...不知道各位是否有更好的方法
      

  3.   

    Process currentProcess = Process.GetCurrentProcess(); //得到当前进程的ID
                Process[] procList = Process.GetProcessesByName(currentProcess.ProcessName);//根据进程的名称得到所有进程            foreach (Process proc in procList)
                {
                    //找到相同进程
                    if (proc.Id != currentProcess.Id)
                    {
                        //Do work
                    }
                }
      

  4.   

    Program.cs 里这么写.
     bool createNew;
                    using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
                    {
                        if (createNew)
                        {
                            //是否要先检查更新
                               //Framework.HALiveUpdate.Update(true,(IntPtr)0, false);
                            Application.EnableVisualStyles();
                            Application.SetCompatibleTextRenderingDefault(false);
                            Application.Run(new FormLogIn());
                        }
                        else
                        {
                            MessageBox.Show("程序已经运行,请不要重复打开!");
                        }
                    }
      

  5.   

    string name = Application.ProductName;
    Process[] prc = Process.GetProcessesByName(name);
    if (prc.Length > 1)
    {
      MessageBox.Show("当前程序已启动");
      return;
    }
      

  6.   


    这种方式不稳妥,如果运行时exe的名称改了,就检测不出来了