多线程09-Mutex

    class Program
    {
        static void Main()
        {
            const string MutexName = "CSharpThreadingCookbook";
            using (var m = new Mutex(false, MutexName))
            {
                if (!m.WaitOne(TimeSpan.FromSeconds(5)))
                {
                    Console.WriteLine("second instance is runing");
                }
                else
                {
                    Console.WriteLine("Runing");
                    Console.ReadKey();
                    m.ReleaseMutex();
                }
            }
        }
    }
posted @ 2016-06-20 17:00  shidengyun  阅读(103)  评论(0编辑  收藏  举报