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.

Subprocess always restarts

Post Reply
KessiJones
Posts: 5
Joined: Wed Apr 28, 2021 12:05 pm

Subprocess always restarts

Post by KessiJones »

Hello,

i've created an Application based on VCL, which has many Windows-Dialogs and implements a WebPage over CEF4Delphi when you click on one Menu entry.

At the beginning my DPR contains the following code to Raise up CEF

Code: Select all

    GlobalCEFApp := TCefApplicationCore.Create;
    GlobalCEFApp.FrameworkDirPath := 'CEF4Runtime';
    GlobalCEFApp.ResourcesDirPath := 'CEF4Runtime';
    GlobalCEFApp.LocalesDirPath := 'CEF4Runtime';
    GlobalCEFApp.FlashEnabled := False;
    GlobalCEFApp.EnablePrintPreview := True;
    GlobalCEFApp.EnableGPU := True;
    GlobalCEFApp.SitePerProcess := False;
    GlobalCEFApp.EnableMediaStream := False;
    GlobalCEFApp.EnableSpeechInput := False;
    GlobalCEFApp.EnableHighDPISupport := False;
    GlobalCEFApp.DisableSpellChecking := True;

    GlobalCEFApp.AddCustomCommandLine('--force-device-scale-factor', '0.8');

    GlobalCEFApp.BrowserSubprocessPath := 'CEF4Runtime\MyBrowser.exe';

    try
        if not GlobalCEFApp.StartMainProcess then
        begin
            Exit;
        end;
    finally
    	GlobalCEFApp.Destroy;
    	GlobalCEFApp := nil;
    end;
When i run my application, the wait cursor starts blinking an in the task manager i see my application and as subprocess the MyBrowser.exe, but the Subprocess is always destroyed and starts again with a new PID.

My MyBroser.exe is actually a empty exe with NO SourceCode.

I also tried to put the sourcecode above to an seerate unit, as shown in the SubProcess-Demo and put it also to the MyBrowser.exe.
But the behaviour is the same.

Can anyone tell me what's wrong ?
User avatar
salvadordf
Posts: 4374
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Subprocess always restarts

Post by salvadordf »

Hi,

You need to delete the "NOT" in the "if not GlobalCEFApp.StartMainProcess then" line and move all the code that initializes "Application", creates your forms and calls "Application.Run" to the begin-end clause that is executed when GlobalCEFApp.StartMainProcess returns TRUE.

See the code examples here :
https://www.briskbard.com/index.php?lang=en&pageid=cef#usage

You can also use one of the demos as a template for your application.
KessiJones
Posts: 5
Joined: Wed Apr 28, 2021 12:05 pm

Re: Subprocess always restarts

Post by KessiJones »

Sorry, but the Code, initializing the Application follows after the "if not GlobalCEFApp.StartMainProcess then" line.
Last edited by KessiJones on Fri Apr 30, 2021 11:52 am, edited 1 time in total.
KessiJones
Posts: 5
Joined: Wed Apr 28, 2021 12:05 pm

Re: Subprocess always restarts

Post by KessiJones »

salvadordf wrote: Thu Apr 29, 2021 3:24 pm Hi,

You need to delete the "NOT" in the "if not GlobalCEFApp.StartMainProcess then" line and move all the code that initializes "Application", creates your forms and calls "Application.Run" to the begin-end clause that is executed when GlobalCEFApp.StartMainProcess returns TRUE.

See the code examples here :
https://www.briskbard.com/index.php?lang=en&pageid=cef#usage

You can also use one of the demos as a template for your application.
Sorry, but the Code, initializing the Application follows after the "if not GlobalCEFApp.StartMainProcess then" line.
Looks like this:

Code: Select all

try
        if not GlobalCEFApp.StartMainProcess then
        begin
            Exit;
        end;
        
        ... Rest of Code initializing the Application and Starting the Main Window ...
        
    finally
    	GlobalCEFApp.Destroy;
    	GlobalCEFApp := nil;
    end;

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

Re: Subprocess always restarts

Post by salvadordf »

The EXE for the subprocesses needs to have some code to initialize CEF on each subprocess.

See this example :
https://github.com/salvadordf/CEF4Delphi/blob/master/demos/Delphi_VCL/ToolBoxSubProcessBrowser/ToolBoxSubProcessBrowser_sp.dpr
Post Reply