We know that some applications can be opened repeatedly, some can only open one, I have written before the program in order to prevent users to open more than one program, is to go through the process of finding processes, now looks really unprofessional, today look at the great God's crack analysis article, know the mutex, Get to the new method from.
<summary>/// The main entry point of the application. // </summary> [STAThread] static void Main () { bool isapprunning = false; System.Threading.Mutex Mutex = new System.Threading.Mutex (True, System.Diagnostics.Process.GetCurrentProcess (). ProcessName, out isapprunning); if (!isapprunning) { MessageBox.Show ("This program is already running, don't make any more noise!") "); Environment.exit (1); } else { application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (New Form1 ()); } }
Be aware of multi-user system problems, which may not be as effective as mutexes, but should rarely be encountered.
Reference:
Http://blog.sina.com.cn/s/blog_6b965dd70101lkwj.html
Http://www.cnblogs.com/huanghai223/archive/2011/09/02/2163520.html
Recognition of Mutex objects in C #