读书人

c#同1时刻仅运行一个实例

发布时间: 2012-09-03 09:48:39 作者: rapoo

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("实例已经运行");                }            }       }    }}

?

读书人网 >C#

热点推荐