Skip to content

Commit 21d272f

Browse files
committed
CefSharp.Test - Call Cef.Shutdown on the same thread that created the CefSharpFixture instance
1 parent 136c98b commit 21d272f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

CefSharp.Test/CefSharpFixture.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
//
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

5-
using CefSharp.OffScreen;
65
using System;
76
using System.IO;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using CefSharp.OffScreen;
810

911
namespace CefSharp.Test
1012
{
1113
public class CefSharpFixture : IDisposable
1214
{
15+
private readonly TaskScheduler scheduler;
16+
private readonly Thread thread;
17+
1318
public CefSharpFixture()
1419
{
20+
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
21+
22+
scheduler = TaskScheduler.FromCurrentSynchronizationContext();
23+
thread = Thread.CurrentThread;
24+
1525
if (!Cef.IsInitialized)
1626
{
1727
var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain();
@@ -32,9 +42,17 @@ public CefSharpFixture()
3242

3343
public void Dispose()
3444
{
35-
if (Cef.IsInitialized)
45+
var factory = new TaskFactory(scheduler);
46+
47+
if (thread.IsAlive)
3648
{
37-
Cef.Shutdown();
49+
factory.StartNew(() =>
50+
{
51+
if (Cef.IsInitialized)
52+
{
53+
Cef.Shutdown();
54+
}
55+
});
3856
}
3957
}
4058
}

0 commit comments

Comments
 (0)