Page 2 of 2

Re: Second instance of .exe fails

Posted: Tue Jan 16, 2024 3:16 pm
by Maksym
Thank you so much! I finally got it all working!

Re: Second instance of .exe fails

Posted: Tue Mar 05, 2024 10:49 am
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

Re: Second instance of .exe fails

Posted: Tue Mar 05, 2024 1:03 pm
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.

Re: Second instance of .exe fails

Posted: Tue Mar 05, 2024 1:49 pm
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)

Re: Second instance of .exe fails

Posted: Wed Mar 06, 2024 8:00 am
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?

Re: Second instance of .exe fails

Posted: Wed Mar 06, 2024 11:09 am
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';

Re: Second instance of .exe fails

Posted: Thu Mar 07, 2024 7:39 am
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?

Re: Second instance of .exe fails

Posted: Thu Mar 07, 2024 8:20 am
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.

Re: Second instance of .exe fails

Posted: Thu Mar 07, 2024 9:08 am
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?

Re: Second instance of .exe fails

Posted: Thu Mar 07, 2024 11:36 am
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.