Skip to content

Commit 80753eb

Browse files
committed
Core - MethodRunnerQueue use TaskCreationOptions.HideScheduler to
To prevent subtasks from attempting to use our LimitedConcurrencyLevelTaskScheduler we need to specify TaskCreationOptions.HideScheduler when creating the Task Resolves #3293
1 parent 40fc9f8 commit 80753eb

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

CefSharp.Example/JavascriptBinding/AsyncBoundObject.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ public int Div(int divident, int divisor)
3131
return divident / divisor;
3232
}
3333

34+
public string DivWithBlockingTaskCall(int dividend, int divisor)
35+
{
36+
var taskToWaitOn = ExecuteTaskBeforeDivision(dividend, divisor);
37+
taskToWaitOn.Wait();
38+
return taskToWaitOn.Result;
39+
}
40+
41+
private async Task<string> ExecuteTaskBeforeDivision(int dividend, int divisor)
42+
{
43+
await RunAsync();
44+
return (dividend / divisor).ToString();
45+
}
46+
47+
private Task RunAsync()
48+
{
49+
return Task.Run(() => Run());
50+
}
51+
52+
private void Run()
53+
{
54+
Debug.WriteLine("AsyncBoundObject Run execution.");
55+
}
56+
3457
public string Hello(string name)
3558
{
3659
return "Hello " + name;

CefSharp.Example/Resources/BindingTestAsync.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
});
6262
});
6363

64+
QUnit.test("Async call (Div with Blocking Task 16 / 2):", function (assert)
65+
{
66+
var asyncCallback = assert.async();
67+
68+
boundAsync.divWithBlockingTaskCall(16, 2).then(function (actualResult)
69+
{
70+
const expectedResult = 8
71+
72+
assert.equal(expectedResult, actualResult, "Divide 16 / 2 resulted in " + expectedResult);
73+
74+
asyncCallback();
75+
});
76+
});
77+
6478
QUnit.test("Async call (Divide 16 /0)", function (assert)
6579
{
6680
var asyncCallback = assert.async();

CefSharp/Internals/MethodRunnerQueue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class MethodRunnerQueue : IMethodRunnerQueue
1313
{
1414
//Limit to 1 task per methodRunnerQueue
1515
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/d0bcb415-fb1e-42e4-90f8-c43a088537fb/aborting-a-long-running-task-in-tpl?forum=parallelextensions
16-
private readonly TaskFactory methodRunnerQueueTaskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(1));
16+
private readonly LimitedConcurrencyLevelTaskScheduler taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
1717
private readonly JavascriptObjectRepository repository;
1818
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
1919

@@ -32,7 +32,7 @@ public void Dispose()
3232

3333
public void Enqueue(MethodInvocation methodInvocation)
3434
{
35-
methodRunnerQueueTaskFactory.StartNew(() =>
35+
Task.Factory.StartNew(() =>
3636
{
3737
var result = ExecuteMethodInvocation(methodInvocation);
3838

@@ -41,7 +41,7 @@ public void Enqueue(MethodInvocation methodInvocation)
4141
{
4242
handler(this, new MethodInvocationCompleteArgs(result));
4343
}
44-
}, cancellationTokenSource.Token);
44+
}, cancellationTokenSource.Token, TaskCreationOptions.HideScheduler, taskScheduler);
4545
}
4646

4747
private MethodInvocationResult ExecuteMethodInvocation(MethodInvocation methodInvocation)

0 commit comments

Comments
 (0)