Methods to prevent repeated startup in. Net

Source: Internet
Author: User
Repeat

Recurring startup problems can be frustrating sometimes, especially with the socket port for the service, which needs to be registered, and when you start the service, the port is registered, and if it starts again, it's obviously a threat to the application that's started.

If we can have a method that, when the application loads, finds that the program is already running, close the program

private static void Checkrunning ()
{
int proceedingcount = 0;
System.diagnostics.process[] processes;
processes = System.Diagnostics.Process.GetProcessesByName ("MyServer");

foreach (System.Diagnostics.Process isprocedding in processes)
{
if (isprocedding.processname== "Myserve")
{
Proceedingcount + 1;
}
}
if (Proceedingcount > 1)
{
DialogResult result;
Result=messagebox.show ("Service has been opened", "hint", messageboxbuttons.ok,messageboxicon.information);

foreach (System.Diagnostics.Process myprocess in processes)
{
Myprocess.kill ();
}

}
}




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.