让程序只运行一个实例的方法

using System.Threading;

public class Class1
{
    [STAThread]
    
static void Main()
    
{
        Mutex mutex 
= new Mutex(false"MutexName");
        
if (!mutex.WaitOne(0false))
        
{
            mutex.Close();
            MessageBox.Show(
"Another instance is aready running!");
            
return;
        }


        Application.Run(
new Form1());
    }

}

posted @ 2005-05-30 21:14  泡面 @ 幸福  阅读(317)  评论(0编辑  收藏  举报