Recognition of Mutex objects in C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.