读书人

只得启动单个程序

发布时间: 2012-11-21 08:23:26 作者: rapoo

只能启动单个程序

 bool ret;            System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out   ret);            if (ret)            {                System.Windows.Forms.Application.EnableVisualStyles();   //这两行实现   XP   可视风格                   System.Windows.Forms.Application.DoEvents();                ConfigurationManager.RefreshSection("appSettings");                string storeId = ConfigurationManager.AppSettings["StoreID"];                if (string.IsNullOrEmpty(storeId.Trim()))                {                    FrmInputStoreMsg frm = new FrmInputStoreMsg();                    frm.ShowDialog();                    if (frm.IsSucceed)                    {                        Application.Run(new FrmMain());                    }                }                else                {                    Application.Run(new FrmMain());                }                m.ReleaseMutex();            }            else            {                MessageBox.Show(null, "有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);                // 提示信息,可以删除。                   Application.Exit();//退出程序               }

?

读书人网 >编程

热点推荐