日期:2014-05-18  浏览次数:20852 次

c#同一时刻仅运行一个实例
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Reflection;
using System.Threading;

namespace SingelProsess
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool first = false;
            string name = Assembly.GetEntryAssembly().FullName;
            using (Mutex muten = new Mutex(false, name, out first))
            {
                if (first)
                {
                    Application.Run(new Form1());
                }
                else
                {
                    MessageBox.Show("实例已经运行");
                }
            }
       }
    }
}

?