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

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

Postby fddima » Sat Jun 24, 2017 9:49 pm

AndyB wrote: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?


There is exist only Windows Application or Console application. First doesnt create console, so most time you should prefer this app type, but using Console for debugging can be useful.

WPF apps like WinForms can use Main function as startup object, but this is not enabled by default. So if you already doesnt utilize this, i recommend do it. See WpfOsr sample.

Thing that you really doesnt want is touching excess stuff in child process. This is just doesnt do anything meaningful, but you pay for loading assemblies in best case, and for unwanted inits/objects in worst.

To avoid this, main function can quick test args to determine if it is main browser process and execute another function (or may be even class, not sure how .net 4.5+ speculative background JIT manage profiles and how it deals with /prefetch cmdline arg, which used by chrome) to init WPF/WinForms and perform actions. On other branch of arg test you will end with another function or just CefExecuteProcess call. This would allow for you that child process will not even try JIT unrelated code, as well as load unwanted (wpf) assemblies.

Technically, CefExecuteProcess do same args check, but i'm dislike it interface, because it mix return code with "i'm a main process" - so if child process return -1 for some reason, branch wilk think that it is main process and not error. In my suggestion this will never happens. Also in my programs main process do many things before touching CEF, so it is always good to know which we process running.
fddima
Master
 
Posts: 774
Joined: Tue Dec 07, 2010 6:10 am

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

Postby AndyB » Wed Jul 05, 2017 1:47 pm

I have a "Startup" function defined in the App.xaml. It gets called on application startup, same as with a main() function.
Yes, i can check the args which i did, it works fine.
I just decided for me that i prefer to have an extra app for the child processes.... i have now about 20 duplicate code lines, but never need to worry about unwanted initializations of objects and unnecessary dll loading.
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 » Wed Jul 05, 2017 2:31 pm

AndyB wrote:I have a "Startup" function defined in the App.xaml. It gets called on application startup, same as with a main() function.
Yes, i can check the args which i did, it works fine.
I just decided for me that i prefer to have an extra app for the child processes.... i have now about 20 duplicate code lines, but never need to worry about unwanted initializations of objects and unnecessary dll loading.


I'm also prefer extra app for child processes. Mainly because this allows clearly split code, so code in renderer don't get chance to call browser-only code. At same time, i'm always guard main process from incorrect usage, as described above.

I'm also worried about unwanted initialization mostly because in my workflows usually it is used to perform bulk crawl-like operations and there is area where you basically want avoid all not needed work, because spawning of child process is already extremely high-cost operation. Sometimes i'm even replace renderer process with native to completely remove costs from .net (every .net process creates thread pool for example - and it is 10 threads which never used, but they still claim memory for stack space). Just imagine 100 concurrent renderers which constantly recreates once it finish own job. :)

For UI applications, surely this hidden costs completely invisible or does small influence on startup time.
fddima
Master
 
Posts: 774
Joined: Tue Dec 07, 2010 6:10 am

Previous

Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 2 guests