VB:
简单了,只要在Project的属性里设置"( Make Single Instance Application)生成单个应用实例程序"即可。
VB这样设置之后,再次启动应用程序,正在运行的应用程序被激活。不会弹出消息。
C#:
通过代码实现,修改Program.cs文件:
static class Program { private static Mutex m_Mutex; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool isRunning; m_Mutex = new Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isRunning); if (isRunning) Application.Run(new Form1()); else MessageBox.Show("The application is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }