Skip to content

Commit 37c8c86

Browse files
committed
Close the client channel before closing the ServiceHost
1 parent bf28d21 commit 37c8c86

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

CefSharp/Internals/BrowserProcessServiceHost.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ public Task<JavascriptResponse> EvaluateScriptAsync(int browserId, long frameId,
6060
}).Unwrap();
6161
}
6262

63+
protected override void OnClose(TimeSpan timeout)
64+
{
65+
var task = operationContextTaskCompletionSource.Task;
66+
67+
CloseChannel(task);
68+
69+
base.OnClose(timeout);
70+
}
71+
72+
private void CloseChannel(Task<OperationContext> task)
73+
{
74+
try
75+
{
76+
if (task.IsCompleted)
77+
{
78+
var context = task.Result;
79+
80+
if (context.Channel != null && context.Channel.State == CommunicationState.Opened)
81+
{
82+
context.Channel.Close();
83+
}
84+
}
85+
}
86+
catch (Exception)
87+
{
88+
89+
}
90+
}
91+
6392
protected override void OnClosed()
6493
{
6594
base.OnClosed();

0 commit comments

Comments
 (0)