C#winform中只允许程序运行一个实例

private static System.Threading.Mutex mutex;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool runNew;
            mutex = new System.Threading.Mutex(true, "myproject", out runNew);
            if (runNew)
            {
                mutex.ReleaseMutex();
               // Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("程序已经在运行。");
            }
        }

上一篇:组策略禁止某个程序运行


下一篇:基于OHCI的USB主机 —— OHCI(ED结构)