程序没有运行则运行,若已经运行则不用做任何事了.

解决方案 »

  1.   

    static void Main()
            {
                if (!isRunning("Gserver"))//不存在才运行.
                {                Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Gserver());
                }
            }        //根据进程名称判断是否有同名进程正在运行中
            private static bool isRunning(string processName)
            {
                return (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1) ? true : false;
            }
      

  2.   

    控制进程只运行一个实例代码请参考这个网址 
    http://www.cnblogs.com/gengchengxiang/articles/991666.html
      

  3.   

    单件模式或者使用多线程的互斥体技术
    这个是互斥体技术
    Boolean createdNew; //返回是否赋予了使用线程的互斥体初始所属权
                System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); //同步基元变量
                if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体
                {
                    Application.Run(new Form1()); /s/这句是系统自动写的
                    instance.ReleaseMutex();
                }
                else
                {
                    MessageBox.Show("已经启动了一个程序,请先退出!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    Application.Exit();
                }
      

  4.   

    单件模式你可以看看这篇文章
    http://terrylee.cnblogs.com/archive/2005/12/09/293509.html
      

  5.   

      static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                if (runone())
                Application.Run(new Form2
                    ());
            }
            private static System.Threading.Mutex mutex;
            private static bool runone()
            {
                bool one;
                mutex = new System.Threading.Mutex(true, "WindowsApplication2", out   one);
                return one;
            }
        }我记得前几天有人刚问过这个问题...在Program.cs理.