Page 1 of 1

Subprocess always restarts

Posted: Thu Apr 29, 2021 9:57 am
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 ?

Re: Subprocess always restarts

Posted: Thu Apr 29, 2021 3:24 pm
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.

Re: Subprocess always restarts

Posted: Thu Apr 29, 2021 6:38 pm
by KessiJones
Sorry, but the Code, initializing the Application follows after the "if not GlobalCEFApp.StartMainProcess then" line.

Re: Subprocess always restarts

Posted: Fri Apr 30, 2021 11:51 am
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;


Re: Subprocess always restarts

Posted: Sat May 01, 2021 10:19 am
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