Dienstag, 11. Dezember 2018

how to avoid multiple executions of a program

Define any unique ID / UID like 'a2c204cc-50a1-4fde-b47f-5b712821edf3' . If this UID isn't free, abort the application. Otherwise block it with the current process.

prepare application

public static System.Threading.Mutex mutex;
public static bool createdNewMutex;

startup application

mutex = new System.Threading.Mutex(true, "a2c204cc-50a1-4fde-b47f-5b712821edf3", out createdNewMutex);
if (!createdNewMutex) base.Shutdown(0);

final exit of the application:

if (App.createdNewMutex) App.mutex.ReleaseMutex();

Keine Kommentare:

Kommentar veröffentlichen