C # prohibit the same client from starting again, but allow the same process of different clients to start

Source: Internet
Author: User

When a client is installed, it is not allowed to be started multiple times. However, when more than two clients are installed, it is allowed to run simultaneously, and each client can only run once.

First, judge the number of processes running. when the process is not running, it is started. When the number of processes running is greater than 1, read the path of each process and determine whether the path is repeated. If there are duplicates, it is not allowed to start, then run and start.

# Region determine whether the system is started
String STR = "";
STR = system. Diagnostics. process. getcurrentprocess (). processname;
System. Diagnostics. Process [] myprocesseslist = system. Diagnostics. process. getprocessesbyname (STR); // obtain the specified process name
Int listlength = myprocesseslist. length;
String [] processesfile = new string [listlength];
If (listlength> 1)
{
For (INT I = 0; I <listlength; I ++)
{
System. Diagnostics. Process PRC = myprocesseslist [I];
Processesfile [I] = PRC. mainmodule. filename;
}
Bool loginflog = false;
For (int K = 0; k <listlength; k ++)
{
For (Int J = k + 1; j <listlength; j ++)
{
If (processesfile [k] = processesfile [J])
{
Loginflog = true;
Break;
}
}
}
If (loginflog)
{
MessageBox. Show ("the program has been started", "prompt", messageboxbuttons. OK, messageboxicon. Error );
Return;
}
}
# Endregion

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.