Skip to content

Commit 37bee96

Browse files
authored
Merge 11449f6 into 002edfb
2 parents 002edfb + 11449f6 commit 37bee96

2 files changed

Lines changed: 39 additions & 24 deletions

File tree

‎CefSharp.Core/ManagedCefBrowserAdapter.cpp‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5286
void 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)

‎CefSharp.Core/ManagedCefBrowserAdapter.h‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace CefSharp
3939

4040
private:
4141
void MethodInvocationComplete(Object^ sender, MethodInvocationCompleteArgs^ e);
42+
void InitializeBrowserProcessServiceHost(IBrowser^ browser);
43+
void DisposeBrowserProcessServiceHost();
4244

4345
internal:
4446
MCefRefPtr<ClientAdapter> GetClientAdapter();
@@ -93,17 +95,9 @@ namespace CefSharp
9395
_browserWrapper = nullptr;
9496
}
9597

96-
if (CefSharpSettings::WcfEnabled && _browserProcessServiceHost != nullptr)
98+
if (CefSharpSettings::WcfEnabled)
9799
{
98-
if (CefSharpSettings::WcfTimeout > TimeSpan::Zero)
99-
{
100-
_browserProcessServiceHost->Close(CefSharpSettings::WcfTimeout);
101-
}
102-
else
103-
{
104-
_browserProcessServiceHost->Abort();
105-
}
106-
_browserProcessServiceHost = nullptr;
100+
DisposeBrowserProcessServiceHost();
107101
}
108102

109103
_webBrowserInternal = nullptr;

0 commit comments

Comments
 (0)