@@ -49,6 +49,40 @@ void ManagedCefBrowserAdapter::CreateBrowser(IWindowInfo^ windowInfo, BrowserSet
4949 delete windowInfo;
5050}
5151
52+ void ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost (IBrowser^ browser)
53+ {
54+ _browserProcessServiceHost = gcnew BrowserProcessServiceHost (_javaScriptObjectRepository, Process::GetCurrentProcess ()->Id , browser->Identifier , _javascriptCallbackFactory);
55+ // NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
56+ // an exception about the process already being closed. Two relevant issues are #862 and #804.
57+ if (_browserProcessServiceHost->State == CommunicationState::Created)
58+ {
59+ try
60+ {
61+ _browserProcessServiceHost->Open ();
62+ }
63+ catch (Exception^)
64+ {
65+ // Ignore exception as it's likely cause when the browser is closing
66+ }
67+ }
68+ }
69+
70+ void ManagedCefBrowserAdapter::DisposeBrowserProcessServiceHost ()
71+ {
72+ if (_browserProcessServiceHost != nullptr )
73+ {
74+ if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
75+ {
76+ _browserProcessServiceHost->Close (CefSharpSettings::WcfTimeout);
77+ }
78+ else
79+ {
80+ _browserProcessServiceHost->Abort ();
81+ }
82+ _browserProcessServiceHost = nullptr ;
83+ }
84+ }
85+
5286void ManagedCefBrowserAdapter::OnAfterBrowserCreated (IBrowser^ browser)
5387{
5488 if (!_isDisposed)
@@ -61,20 +95,7 @@ void ManagedCefBrowserAdapter::OnAfterBrowserCreated(IBrowser^ browser)
6195
6296 if (CefSharpSettings::WcfEnabled)
6397 {
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- }
98+ InitializeBrowserProcessServiceHost (browser);
7899 }
79100
80101 if (_webBrowserInternal != nullptr )
0 commit comments