Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to allow only one instance?

Post Reply
User avatar
danicarla2
Posts: 19
Joined: Mon Oct 01, 2018 6:01 pm
Location: Brazil

How to allow only one instance?

Post 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?
User avatar
salvadordf
Posts: 4575
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to allow only one instance?

Post 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.
Post Reply