读书人

互斥体(mutex类)有关问题

发布时间: 2012-01-14 20:02:35 作者: rapoo

互斥体(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;



namespace EnumlDrives
{
static class Program
{
static bool f;
static Mutex m;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
m = new Mutex(false, "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 Form1());
}
}
}

读书人网 >C#

热点推荐