问题如题,望高手指教!!

解决方案 »

  1.   


    [STAThread]
            static void Main()
            {
                bool bExist;
                //使用指示调用线程是否应拥有互斥体的初始所属权的布尔值、作为互斥体名称的字符串以及在方法返回时指示调用线程是否已被授予互斥体的初始所属权的布尔值来初始化 Mutex 类的新实例。
                Mutex MyMutex = new Mutex(true, "test", out bExist);
                if (bExist)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                    MyMutex.ReleaseMutex();
                }
                else
                {
                    MessageBox.Show("程序已经运行", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
      

  2.   

    static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                int iProcessNum = 0;            foreach (Process singleProc in Process.GetProcesses())
                {
                    if (singleProc.ProcessName == Process.GetCurrentProcess().ProcessName)
                    {
                        iProcessNum += 1;
                    }
                }
                if (iProcessNum == 2)
                {
                    MessageBox.Show("【系统提示】:程序已经在运行中……", "巨安电子技术", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (iProcessNum > 2)
                {
                    return;
                }
                else
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new fmLogin());
                }
            }
        }