简单的只运行一个程序实例[原创]

 1using System;
 2using System.Collections.Generic;
 3using System.Windows.Forms;
 4using BOM.NewUI;
 5using System.Threading;
 6
 7namespace NewUI
 8{
 9    static class Program
10    {
11        /// <summary>
12        /// 应用程序的主入口点。
13        /// </summary>

14        [STAThread]
15        static void Main()
16        {
17            try
18            {
19                //声明互斥体。   
20                Mutex mutex = new Mutex(false"ThisShouldOnlyRunOnce");
21                //判断互斥体是否使用中。   
22                bool running = !mutex.WaitOne(0false);
23                if (!running)
24                {
25                    log4net.Config.XmlConfigurator.Configure();
26                    Application.EnableVisualStyles();
27                    Application.SetCompatibleTextRenderingDefault(false);
28                    Thread.CurrentThread.Name = "GUI Main Thread";
29                    Application.Run(new MainContext());
30                }

31            }

32            catch (Exception ex)
33            {
34                MessageBox.Show(ex.ToString());
35                log4net.LogManager.GetLogger("Main Thread").Error("error:", ex);
36
37            }

38         }

39
40
41    }

42}
posted @ 2008-02-18 14:15  Simmy.卧龙先生  阅读(373)  评论(1编辑  收藏  举报