How to check already running exe in C # .net?

What is the procedure to know that when each user launches the application, he checks to see if the instance is running. If it does not start, it will start it, otherwise it will focus on the current one. I already tried the code for the singleton application, but it gave a lot of errors. it does not work properly. can i provide another alternative solution for this?

+3
source share
4 answers

You should use the class Mutexas described here: Best way to implement singleton in a C # console application?

EDIT: I have this in my code:

class Program
{
    public const string AppName = "...";
    private static readonly Mutex mutex = new Mutex(true, Program.AppName);

    public Program()
    {
        if (!mutex.WaitOne(TimeSpan.Zero, true))
            throw new ApplicationException("Another instance already running");
    }
}
+3
source

Mutex.

. Mutex, , , .

+1
+1

, . backgroundWorker , .

0

Source: https://habr.com/ru/post/1730977/


All Articles