WinForm限制客户程序只能运行一个实例

WinForm限制客户程序只能运行一个实例;

using System;
using System.Threading;

static void Main() 
{
      bool create = false;
      using (Mutex mu = new Mutex(true, Application.ProductName, out create))
      {
                if (create)
                {
                   Application.Run( new MainForm() );  
                }
                else
                {
                    MessageBox.Show("程序已经在运行,请不要重复打开!");
                    Application.Exit();  
                }
       }
}

希望以上分享对初学朋友有些帮助,谢谢!
更多关注付义方技术博客:http://blog.csdn.net/fuyifang
或者直接用手机扫描二维码查看更多博文:

你可能感兴趣的:(WinForm,运行一个实例)