[System.Runtime.InteropServices.DllImport("Kernel32.dll",EntryPoint="CreateEvent")] public static extern int CreateEvent(IntPtr a,bool bManualReset,bool bInitialState,string strName); [System.Runtime.InteropServices.DllImport("Kernel32.dll",EntryPoint="GetLastError")] public static extern int GetLastError(); [STAThread] static void Main() { int Handle = CreateEvent(IntPtr.Zero,true,true,"Card"); if(GetLastError()==183) return; Application.Run(new Form1()); }
using System.Threading; bool bCreatedNew; //Create a new mutex using specific mutex name Mutex m =new Mutex( false, "yourprogramName", out bCreatedNew ); if( bCreatedNew ) //未运行 Application.Run(new yourFormName());
public static extern int CreateEvent(IntPtr a,bool bManualReset,bool bInitialState,string strName); [System.Runtime.InteropServices.DllImport("Kernel32.dll",EntryPoint="GetLastError")]
public static extern int GetLastError();
[STAThread]
static void Main()
{
int Handle = CreateEvent(IntPtr.Zero,true,true,"Card");
if(GetLastError()==183)
return;
Application.Run(new Form1());
}
bool bCreatedNew;
//Create a new mutex using specific mutex name
Mutex m =new Mutex( false, "yourprogramName", out bCreatedNew );
if( bCreatedNew ) //未运行
Application.Run(new yourFormName());
http://dev.csdn.net/article/15/15598.shtm