Application is started by CefGlue or CEF on each navigation

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Application is started by CefGlue or CEF on each navigation

Postby AndyB » Sat Jun 10, 2017 5:57 pm

I noticed a very strange behavior.
On each navigation the app gets started!

You can check this by adding debug code in Program.cs in the WinForm and WPF sample app:
Code: Select all
System.IO.StreamWriter sw = null;
try
{
   sw = System.IO.File.AppendText("E:\\log.txt");
   sw.Write("app started\r\n");
   sw.Flush();
}
finally
{
   if (sw != null)
   {
      sw.Close();
      sw.Dispose();
   }
}


On starting the app, the app gets started twice.
Each time you enter a new url and click enter the app gets started again.
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Application is started by CefGlue or CEF on each navigat

Postby salvadordf » Sun Jun 11, 2017 3:13 am

Hi,

I don't know CefGlue but that's normal in other cef bindings when you configure CEF to use multiple processes.

http://www.chromium.org/developers/desi ... ess-models
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: Application is started by CefGlue or CEF on each navigat

Postby AndyB » Sun Jun 11, 2017 4:32 pm

Thank you for this VERY important info!
I think i understand now why the CEF init code is the very 1st code in Program.cs in your samples...
If the app was started by CEF then CefRuntime.Load() and CefRuntime.ExecuteProcess() MUST be executed at the earliest possible code line.
If i close my app then the CEF initiated process seems to get aborted, no code after ExecuteProcess() gets executed. Is this correct?
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Application is started by CefGlue or CEF on each navigat

Postby salvadordf » Tue Jun 13, 2017 3:59 am

As I said in my previous comment, I know nothing about CefGlue and I can't give you a precise answer.

All the CEF bindings that I've seen have a similar code structure to this :
https://bitbucket.org/chromiumembedded/ ... neralUsage

Even if you can't apply all that directly, it's highly recommended that you read it.

I hope this helps.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: Application is started by CefGlue or CEF on each navigat

Postby fddima » Wed Jun 21, 2017 8:18 am

AndyB wrote:Thank you for this VERY important info!
I think i understand now why the CEF init code is the very 1st code in Program.cs in your samples...
If the app was started by CEF then CefRuntime.Load() and CefRuntime.ExecuteProcess() MUST be executed at the earliest possible code line.
If i close my app then the CEF initiated process seems to get aborted, no code after ExecuteProcess() gets executed. Is this correct?


In browser process: It is executed always. Because it is returns immediately. :)

In renderer process: Code after ExecuteProcess may be executed, but not guaranteed. Somerhing like: If chrome's child process see that it is can use "shortcircuited" close - it is terminates self. This saves CPU from execution of not needed shutdown logic (OS do it anyway). This is why any shutdown-like code in renderer may be executed, but not guaranteed (OnBrowserDestroyed callback for example plays by same rules).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Application is started by CefGlue or CEF on each navigat

Postby AndyB » Thu Jun 22, 2017 3:39 pm

I probably don't fully understand what you mean.

I have created now a very small app for the sub-processes which gets stated by CEF with CefRuntime.ExecuteProcess() as last statement.

In my "main" app, i additionally call CefRuntime.Initialize(), and CefRuntime.Shutdown() on application exit,
and Dispose() all created browsers before Shutdown() to get the sub-processes and my app closed properly.

This seems to work fine so far...i don't need to take special care about my app to get started multiple times, which i really don't like if not absolutely necessary.
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Application is started by CefGlue or CEF on each navigat

Postby fddima » Fri Jun 23, 2017 12:51 am

AndyB wrote:I probably don't fully understand what you mean.

I have created now a very small app for the sub-processes which gets stated by CEF with CefRuntime.ExecuteProcess() as last statement.

In my "main" app, i additionally call CefRuntime.Initialize(), and CefRuntime.Shutdown() on application exit,
and Dispose() all created browsers before Shutdown() to get the sub-processes and my app closed properly.

This seems to work fine so far...i don't need to take special care about my app to get started multiple times, which i really don't like if not absolutely necessary.


You are right. My answer was mostly about your last phrase "If i close my app then the CEF initiated process seems to get aborted, no code after ExecuteProcess() gets executed. Is this correct?". I just clarify that in *child processes* code after ExecuteProcess MAY (i.e. optionally) be executed, as well as terminated very deeply in chromium code (that you say). And this is depends from timings and chrome decisions. In case when main process terminated, i think that child process favor terminate early also, but there is no exist any guarantees about. Also childs favor terminate if you close/navigate out to another domain and fresh renderer is requested. But, again, under some situations you can eventually get absolutely fair shutdown (with code after ExecuteProcess execution).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Application is started by CefGlue or CEF on each navigat

Postby AndyB » Fri Jun 23, 2017 3:22 pm

Thank you for explaining this again.
Good to know, i have added now Application.Current.Shutdown() in my child process app after CefRuntime.ExecuteProcess() to ensure that the child process gets really closed in any case.
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Re: Application is started by CefGlue or CEF on each navigat

Postby fddima » Fri Jun 23, 2017 3:31 pm

AndyB wrote:Thank you for explaining this again.
Good to know, i have added now Application.Current.Shutdown() in my child process app after CefRuntime.ExecuteProcess() to ensure that the child process gets really closed in any case.

Hm... no, Application.Current is something from winfroms? You not need call it in childs. Just returns from Main is enough. Or some managing custom actions if you have.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Application is started by CefGlue or CEF on each navigat

Postby AndyB » Fri Jun 23, 2017 4:42 pm

I have a WPF application.
Application.Current.Shutdown() may be WPF specific, don't know if that exists in WinForms too.

My child process app is also a WPF app, just thought it may be better to have the same type as my main app.
But probably a console app would also work fine?
AndyB
Techie
 
Posts: 39
Joined: Sun Apr 16, 2017 3:00 pm

Next

Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 10 guests