程序互斥怎么做?我用System.Threading.Mutex mutex = new System.Threading.Mutex(false, "1111213213508")没效果.内详
我想让一个程序只能运行一次.执行文件名可能更改的情况下.
我的环境是vs2005.我在program.cs中的main方法中加入以下代码:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//声明互斥体。
System.Threading.Mutex mutex = new System.Threading.Mutex(false, "123213213");
//判断互斥体是否使用中。
bool Running = !mutex.WaitOne(0, false);
if (!Running)
{
//Application.Run(new Form1());
Application.Run(new UserLogin());
}
else
{
MessageBox.Show("程序已经在运行");
}
但是当我一个程序是从ide的启动程序(不管是调试还是释放模式)运行后在在生成的目录下运行就会有效果.程序会提示"程序已经在运行".但是当我直接在生成目录中多次运行却没有任何效果.为什么??