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.

Program still working in task manager

wngchi
Posts: 4
Joined: Wed Jan 25, 2023 1:12 am

Program still working in task manager

Post by wngchi »

Hello:
I use CEF4Delphi ver 91, the example program MiniBrowser, to generate the executable file, but when the MiniBrowser window is closed, the program will occasionally still be running as an task manager, and the program does not completely end.

When the program loads a web page (eg: https://tw.yahoo.com/), it closes when the page has not been completed
MiniBrowser window is prone to the above phenomena.

So I want to stop the program for 0.5~1 second before calling DestroyGlobalCEFApp, which can "reduce" this situation.


Code: Select all

if (exepath.Substring(0,1).toupper='C') or (exepath.Substring(0,1).toupper='D') then begin
      CreateGlobalCEFApp;

      if GlobalCEFApp.StartMainProcess then
        begin
          Application.Initialize;
          {$IFDEF DELPHI11_UP}
            Application.MainFormOnTaskbar := True;
          {$ENDIF}
          Application.CreateForm(TMiniBrowserFrm, MiniBrowserFrm);
          Application.CreateForm(TPreferencesFrm, PreferencesFrm);
          Application.CreateForm(TSimpleTextViewerFrm, SimpleTextViewerFrm);
          Application.CreateForm(TFindFrm, FindFrm);
          Application.Run;
        end;

      
        try
          //2022/10/9
        
            TThread.Sleep(500);   // sleep 0.5 second
            DestroyGlobalCEFApp;

            //GlobalCEFApp.Free;


        except
            on e : exception do begin
              showmessage(e.Message);
            end;
        end;
    end else begin
         showmessage('請在c 或 D 磁碟執行本程式');
    end;

why is this? THX
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Program still working in task manager

Post by salvadordf »

Hi,

Please, upgrade to the latest CEF4Delphi version available at GitHub :
https://github.com/salvadordf/CEF4Delphi/archive/refs/heads/master.zip

Add some breakpoints in Chromium1BeforeClose, Chromium1Close, FormCloseQuery and FormDestroy to check that the destruction steps are followed correctly.

This is the destruction sequence needed to close MiniBrowser correctly :
https://github.com/salvadordf/CEF4Delphi/blob/9c186829bec6abeea7a16dcf2338b7ac90f33500/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L312
wngchi
Posts: 4
Joined: Wed Jan 25, 2023 1:12 am

Re: Program still working in task manager

Post by wngchi »

Thank you for your reply:
I try to use CEF4Delphi ver 108 to compile MiniBrowser.exe.
Unfortunately, the situation still happened. (status as attachements)

The operating procedure can be downloaded from the following URL:
https://mega.nz/file/4CpGFLxR#zXNBczgrt9LgkdE7JgyLoAeg8-6qaxXhTA35vIAtf9I

I use delphi 10 seattle to compile the program.

The way I do it is as follows:
Close MiniBrowser.exe before the web page is completed.


I will try to think of other ways, or try to upgrade the delphi version.

thx.


---------------------------------------------------------------


I try to use delphi 10.4 to compile the MiniBrowser (CEF4Delphi ver 108 ), but the situation still happens.
You do not have the required permissions to view the files attached to this post.
Last edited by wngchi on Fri Jan 27, 2023 10:47 am, edited 4 times in total.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Program still working in task manager

Post by salvadordf »

I could only reproduce this issue once. :oops: In all the other tests MiniBrowser was closed correctly.

I also tried the the TabbedBrowser2 demo because it has a slightly different shutdown sequence to close the tabs and it worked correctly.

Can you try the the official CEF sample application?
https://cef-builds.spotifycdn.com/cef_binary_109.1.18%2Bgf1c41e4%2Bchromium-109.0.5414.120_windows32.tar.bz2
wngchi
Posts: 4
Joined: Wed Jan 25, 2023 1:12 am

Re: Program still working in task manager

Post by wngchi »

hank you for your reply:
I try to use CEF4Delphi ver 109(109.1.16) + delphi 10.4 to compile MiniBrowser.exe.
Unfortunately, the situation still happened. (status as attachements)

The operating procedure can be downloaded from the following URL:
https://mega.nz/file/xb4jURgS#k4qK2CjlYw--jVYAH2NFDe5a8t6DsBA0-dYSb5vpKeA

thx.

ps:
sorry,
I can't use the 109.1.18 dll you provided because the CEF4Delphi source on git is only up to ver 109.1.16 。
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Program still working in task manager

Post by salvadordf »

I'm sorry. I gave you the link to the CEF binaries instead of the CEF sample application.

Please, download this file :
https://cef-builds.spotifycdn.com/cef_binary_109.1.18%2Bgf1c41e4%2Bchromium-109.0.5414.120_windows32_client.tar.bz2

Decompress that file and run cefclient.exe

Test this issue with cefclient.exe
wngchi
Posts: 4
Joined: Wed Jan 25, 2023 1:12 am

Re: Program still working in task manager

Post by wngchi »

hi salvadordf :
cefclient Operating normally.
When the cefclient program is closed, the program ends normally.
no more process in task mamager. :)
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Program still working in task manager

Post by salvadordf »

I could finally reproduce this issue reliably. cefclient is also affected by this issue when you use the --no-sandbox command line switch.

I just created an issue in the CEF repository :
https://bitbucket.org/chromiumembedded/cef/issues/3442/cefclient-fails-to-close-all-processes

Vote for that issue to accelerate the fix and receive a notification when it's fixed.
wngchi
Posts: 4
Joined: Wed Jan 25, 2023 1:12 am

Re: Program still working in task manager

Post by wngchi »

hi,

Because my system is using miniBrowser,
I would like to ask, before the revised version, how can I modify miniBrowser to avoid this problem.

The cefclient.exe health you provided is normal.
thank you very much. :)
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Program still working in task manager

Post by salvadordf »

When we can replicate this issue with the official CEF sample application it means that this is a CEF issue.

cefclient is the official CEF sample application and it should close all the processes when the main form with the embedded web browser is closed.

Some CEF wrappers like CEF4Delphi can't enable a Chromium feature called "sandbox". This is a Delphi limitation because we can't link the cef_sandbox.lib and libcef.lib files found in the CEF binaries.

When we run cefclient with the "--no-sandbox" command line switch then cefclient runs with a disabled sandbox like all the CEF4Delphi demos and then we can see the effects of this issue.

I don't know the exact cause of this issue and I can only guess.
Post Reply