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.

Second instance of .exe fails

Maksym
Posts: 3
Joined: Wed Dec 20, 2023 11:13 am

Re: Second instance of .exe fails

Post by Maksym »

Thank you so much! I finally got it all working!
Bilbo
Posts: 3
Joined: Tue Mar 05, 2024 10:47 am

Re: Second instance of .exe fails

Post by Bilbo »

Hi all,

Is there a way to use more instances of my application or not? If yes, can someone demonstrate how to accomplish this task?

Thanks
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Second instance of .exe fails

Post by salvadordf »

Bilbo wrote: Tue Mar 05, 2024 10:49 am Is there a way to use more instances of my application or not? If yes, can someone demonstrate how to accomplish this task?
Yes. You can run a second instance of your application as long as each instance uses a different cache directory in the GlobalCEFApp.cache property.

If you need to use the same cache and cookies in all your instances then follow the instructions about using a MUTEX in my previous posts on this thread.
Bilbo
Posts: 3
Joined: Tue Mar 05, 2024 10:47 am

Re: Second instance of .exe fails

Post by Bilbo »

Thanks for your answer. Sounds good, does this directory have to exist on the hard drive? Maybe you could provide me a short piece of code to demonstrate that (best practice), also this way with the mutex? (Sorry, but there are so many code snippets in the previous posts)
Last edited by Bilbo on Tue Mar 05, 2024 1:54 pm, edited 2 times in total.
Bilbo
Posts: 3
Joined: Tue Mar 05, 2024 10:47 am

Re: Second instance of .exe fails

Post by Bilbo »

I just created 2 executables that use different caches (GlobalCEFApp.Cache := ...). However, both cannot be started at the same time. Could you perhaps post an example of how this works?
Last edited by Bilbo on Wed Mar 06, 2024 8:20 am, edited 1 time in total.
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Second instance of .exe fails

Post by salvadordf »

Follow these steps :
  • Open the SimpleBrowser2 demo and edit the project source.
  • Add this line before the GlobalCEFApp.StartMainProcess call : GlobalCEFApp.cache := 'cache1';
  • Build SimpleBrowser2.
  • Open the CEF4Delphi\bin directory and rename SimpleBrowser2.exe to SimpleBrowser2-cache1.exe
  • Edit the project source again and set GlobalCEFApp.cache := 'cache2';
  • Build SimpleBrowser2 again.
I just did all this with the latest CEF4Delphi version available at GitHub and both executables worked correctly at the same time.

If necessary, you can also set GlobalCEFApp.RootCache := 'c:\root1'; and then set GlobalCEFApp.cache := 'c:\root1\cache';
The second executable should set GlobalCEFApp.RootCache := 'c:\root2'; and then set GlobalCEFApp.cache := 'c:\root2\cache';
Bilbo
Posts: 3
Joined: Tue Mar 05, 2024 10:47 am

Re: Second instance of .exe fails

Post by Bilbo »

Thank you, that's how it works.
Now I have the problem that I want to delete the cache directory at the end of the application otherwise there would be a lot of directories after a while. But that doesn't work because Chromium still has access to the cache directory even after releasing the instance (CEFApp.Free). How can I accomplish this task?
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Second instance of .exe fails

Post by salvadordf »

Try calling TChromiumCore.ClearCache before closing the application. Wait for the TChromiumCore.OnDevToolsMethodResult event before closing the application.

You can also save a custom setting or registry value to mark that directory as "deletion pending". Then modify the application to delete it before initializing CEF when it starts.

GlobalCEFApp.DeleteCache can also be used to delete the cache before initializing CEF.
Bilbo
Posts: 3
Joined: Tue Mar 05, 2024 10:47 am

Re: Second instance of .exe fails

Post by Bilbo »

I'm not able to call TChromiumCore in my dpr file. I don't think this is of any use to me either because I don't open a browser window. I close the application again immediately after opening it. DeleteCache doesn't help. Any other idea?
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Second instance of .exe fails

Post by salvadordf »

The previous methods to clear the cache is what CEF and Chromium allows us to use.
We can only adapt our applications to the existing CEF methods.
Post Reply