Closed redplane closed 3 years ago
@redplane
Is it a bug of CefSharp ?
Is this about CefGlue or CefSharp? I am assuming CefGlue.
If you will be making lots of advanced changes, I will suggest that you spend sometime understanding CEF process generally, specifically CEF architecture - http://www.chromium.org/developers/design-documents/multi-process-architecture
CEF is multi-process, so yes, what you write in the Program Main method will run for every process. To stop that running for every process, you need sub-process - https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-separate-sub-process-executable
CefSharp has sub-process implemented, CefGlue does not. Chromely used to have sub-process implemented for Windows but since a change in CEF Network Service, that has been discontinued.
A workaround with what you are trying to do is to check for the process running and ensure the method you want invoked is done only for that process. This issue will help - https://github.com/chromelyapps/Chromely/issues/213 Also -
I will suggest:
static void Main(string[] args)
{
var proctype = ClientAppUtils.GetProcessType(args);
AppBuilder
.Create()
.UseApp<XLinkApp>(new XLinkApp(proctype))
.Build()
.Run(args);
}
public class XLinkApp : ChromelyBasicApp
{
private readonly ProcessType _processType;
public XLinkApp(ProcessType processType)
{
_processType = processType;
}
public override void ConfigureServices(IServiceCollection services)
{
// Service registration....
}
public override void Initialize(IServiceProvider serviceProvider)
{
if (_processType == ProcessType.Browser)
UpdateNewContentVersionAsync(serviceProvider).Wait();
base.Initialize(serviceProvider);
}
}
I'm using Chromely for my application, the implementation is below:
As I understand,
ConfigureServices
,Initialize
will only run once when the application start. However, by taking a look at the message on the console, I noticed:On CefGlue child process launch arguments:
is printed multiple timesCalling UpdateNewContentVersionAsync
is printed multiple time.This is annoying because I have some services which are registered as Singleton, one of them is to manage Serial Port connection.
Because of calling multiple
Initialize
,ConfigureServices
, my service access to Serial Port multiple time -> the second one will be prevented from accessing COM Port (due to its busy state).Is it a bug of CefSharp ? Any solution for this ?