Page 1 of 1

How to allow only one instance?

Posted: Mon Aug 10, 2020 2:00 pm
by danicarla2
Hi people!!

I would like to allow the user to run only one instance of the executable.

Considering that the site may have pop-ups? What is the best way to do this?

Re: How to allow only one instance?

Posted: Mon Aug 10, 2020 2:33 pm
by salvadordf
Hi

You can use a named mutex :
https://www.swissdelphicenter.ch/en/showcode.php?id=42

You would only have to check the mutex in the main process and not in other CEF subprocesses.

If you use the same EXE for all processes then the pseudo-code in your DPR file would look like this :

Code: Select all

CreateGlobalCEFApp;
if GlobalCEFApp.StartMainProcess then
begin
  if CheckMyMutex then
  begin
    Application.Initialize;
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
  end;
  DestroyMyMutex;
end;
DestroyGlobalCEFApp;
If you use a different EXE for the subprocesses then you would only add the "CheckMyMutex" and "DestroyMyMutex" calls in the main DPR and not in the DPR for the subprocesses.