Is the mutex object an operating system?

Source: Internet
Author: User

InProgramI have been using this method to control the running of a single instance:

Bool createnew = true;
Using (mutex M = new mutex (false, "X8127891C-CD52-4448-B0FF-AB5E5AA34F15", out createnew ))
{
If (createnew = false)
{
MessageBox. Show ("this program is running and cannot run multiple instances at the same time", "prompt", messageboxbuttons. OK, messageboxicon. Error );
Return;
}

.....

The program has been running well, but a problem was suddenly found some time ago: when using the Remote Desktop login of the operating system, multiple program instances can be created, that is, different sessions can successfully run the program, only one instance can be created in the same session. I checked msdn and said that mutex is at the operating system level. Why?

 

There is no time to explore, but I just made a simple change (although the program with the same name is different, it cannot run at the same time. Fortunately, this program is not a general product and it is unlikely to have the same name ):

Process [] PS = process. getprocessesbyname (process. getcurrentprocess (). processname );
If (PS. length> = 2)
{
MessageBox. Show ("this program is running and cannot run multiple instances at the same time", "prompt", messageboxbuttons. OK, messageboxicon. Error );
Return;
}

.....

 

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.