C# WinForm 程序如何只允许运行一个实例 ?

来源:百度知道 编辑:UC知道 时间:2024/05/19 23:32:35
RT,C# WinForm 程序如何只允许运行一个实例 ?
高手指教 !

楼上的不太好.还写死了"WindowsFormApplication1"

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
ConfigManager.LoadConfiguration();//这里我是读了配置,是否允许多实例
if (Global.GlobalVariable.SingleInstance) //如果配置不允许多实例
{
Process pCurrent = Process.GetCurrentProcess();
Process[] pList = Process.GetProcessesByName(pCurrent.ProcessName);
if (pList.Length >= 2)
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginForm());
}

[STAThread]
static void Main()
{
bool CreateNew;
System.Threading.Mutex mutex = new System.Threading.Mutex(false,