@@ -49,6 +49,42 @@ void ManagedCefBrowserAdapter::CreateBrowser(IWindowInfo^ windowInfo, BrowserSet
4949 delete windowInfo;
5050}
5151
52+ // NOTE: This was moved out of OnAfterBrowserCreated to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
53+ __declspec (noinline) void ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost(IBrowser^ browser)
54+ {
55+ _browserProcessServiceHost = gcnew BrowserProcessServiceHost (_javaScriptObjectRepository, Process::GetCurrentProcess ()->Id , browser->Identifier , _javascriptCallbackFactory);
56+ // NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
57+ // an exception about the process already being closed. Two relevant issues are #862 and #804.
58+ if (_browserProcessServiceHost->State == CommunicationState::Created)
59+ {
60+ try
61+ {
62+ _browserProcessServiceHost->Open ();
63+ }
64+ catch (Exception^)
65+ {
66+ // Ignore exception as it's likely cause when the browser is closing
67+ }
68+ }
69+ }
70+
71+ // NOTE: This was moved out of ~ManagedCefBrowserAdapter to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
72+ __declspec (noinline) void ManagedCefBrowserAdapter::DisposeBrowserProcessServiceHost()
73+ {
74+ if (_browserProcessServiceHost != nullptr )
75+ {
76+ if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
77+ {
78+ _browserProcessServiceHost->Close (CefSharpSettings::WcfTimeout);
79+ }
80+ else
81+ {
82+ _browserProcessServiceHost->Abort ();
83+ }
84+ _browserProcessServiceHost = nullptr ;
85+ }
86+ }
87+
5288void ManagedCefBrowserAdapter::OnAfterBrowserCreated (IBrowser^ browser)
5389{
5490 if (!_isDisposed)
@@ -61,20 +97,7 @@ void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)
6197
6298 if (CefSharpSettings::WcfEnabled)
6399 {
64- _browserProcessServiceHost = gcnew BrowserProcessServiceHost (_javaScriptObjectRepository, Process::GetCurrentProcess ()->Id , browser->Identifier , _javascriptCallbackFactory);
65- // NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
66- // an exception about the process already being closed. Two relevant issues are #862 and #804.
67- if (_browserProcessServiceHost->State == CommunicationState::Created)
68- {
69- try
70- {
71- _browserProcessServiceHost->Open ();
72- }
73- catch (Exception^)
74- {
75- // Ignore exception as it's likely cause when the browser is closing
76- }
77- }
100+ InitializeBrowserProcessServiceHost (browser);
78101 }
79102
80103 if (_webBrowserInternal != nullptr )
0 commit comments