Ensure that only one instance is running .txt

xiaoxiao2021-03-06  18

Mainly use the Process class in the System.Diagnostics name space to implement

Thinking, we are looking for the process in the process before running the program, and the running position is also the same, if you don't run the program, if you have, you will place the same location in the same location.

Main code:

Public Static Process RunningInstance ()

{

Process Current = process.getcurrentProcess ();

Process [] processes = process.getProcesSbyName (current.ProcessName);

/ / Find the process of the same name

Foreach (Process Process In Processes)

{

// Ignore the current process

IF (Process.id! = Current.ID)

{

// Verify that the program running position of the same process is the same.

IF (Assembly.GetexecutingAssembly (). Location.Replace ("/", "//") == current.mainmodule.FileName)

{

// Return the Other process instance.

Return Process;

}

}

}

// no Other instance was found, return null.

Return NULL;

}

转载请注明原文地址:https://www.9cbs.com/read-44196.html

New Post(0)