现在的位置: 首页 > 综合 > 正文

限制只启动一个程序实例

2013年09月12日 ⁄ 综合 ⁄ 共 713字 ⁄ 字号 评论关闭
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace OneCase
{
    
static class Program
    
{
        
/// <summary>
        
/// 应用程序的主入口点。
        
/// </summary>

        [STAThread]
        
static void Main()
        
{
            
bool isNew;
            Mutex m 
= new Mutex(true"MyApp"out isNew);

            
if (isNew)
            
{
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(
false);
                Application.Run(
new Form1());
            }

            
else
            
{
                MessageBox.Show(
"已经存在一个程序实例!");
                Application.Exit();
            }

        }

    }

}

 

抱歉!评论已关闭.