c# 控制台程序单例运行

来源:互联网 发布:巨人网络有哪些手游 编辑:程序博客网 时间:2024/05/21 09:08
    class Program    {        static void Main(string[] args)        {            bool isAppRunning = false;            System.Threading.Mutex mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isAppRunning);            if (!isAppRunning)            {                Console.Write("本程序已经在运行了,请不要重复运行!");                Environment.Exit(1);            }            Console.WriteLine("heihei");            Console.ReadKey();        }    }