日期:2014-05-20  浏览次数:20849 次

互斥体(mutex类)问题
using   System;
using   System.Collections.Generic;
using   System.Windows.Forms;
using   System.Threading;
namespace   mycnc
{
        static   class   Program
        {
                [STAThread]
                static   void   Main()
                {
                        bool   f;
                        Mutex   m   =   new   Mutex(true,   "www.wade.cn ",   out   f);
                        if   (!f)
                        {
                                MessageBox.Show( "河南网通宽带账号扫描程序已经启动! ",
                                                                "提示信息: ",   MessageBoxButtons.OK,  
                                                                  MessageBoxIcon.Asterisk);
                                Application.Exit();
                                return;
                        }
                        else
                        {
                                m.WaitOne();
                        }
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new   Form4   ());
                }
        }
}
//   互斥体(mutex类)问题
//   上述代码中form4窗体是通过   add   ->   existing   item   选项添加的(form4上有控件),
//   如果执行上述代码,具体说是在release方式下执行Form4窗体,那么这个互斥体将不
//   起作用,但是用上述方法添加一个空白窗体却不影响互斥体的执行!难道互斥体和有些
//   控件不能同时存在?
//   另外,如果在debug方式下执行Form4窗体,互斥体也正常运行,难道互斥在release
//   方式下执行有什么限制?
//   请大家看看,谢谢!

//=================================================================


------解决方案--------------------
//这样声明好像就可以了
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;