(C#)絶対に二重起動させない方法
毎回忘れるのでメモ。
この方法だと、絶対に二重起動しない。
Application.Run()がusingの中に入っているのがミソ。
[STAThread] static void Main() { using (Mutex mutex = new Mutex(false, "APP NAME")) { if (mutex.WaitOne(0, false) == false) { MessageBox.Show("二重起動はできません。", "APP NAME"); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } }