mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
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
This commit is contained in:
@@ -31,6 +31,29 @@ namespace CefSharp.Example.JavascriptBinding
|
||||
return divident / divisor;
|
||||
}
|
||||
|
||||
public string DivWithBlockingTaskCall(int dividend, int divisor)
|
||||
{
|
||||
var taskToWaitOn = ExecuteTaskBeforeDivision(dividend, divisor);
|
||||
taskToWaitOn.Wait();
|
||||
return taskToWaitOn.Result;
|
||||
}
|
||||
|
||||
private async Task<string> ExecuteTaskBeforeDivision(int dividend, int divisor)
|
||||
{
|
||||
await RunAsync();
|
||||
return (dividend / divisor).ToString();
|
||||
}
|
||||
|
||||
private Task RunAsync()
|
||||
{
|
||||
return Task.Run(() => Run());
|
||||
}
|
||||
|
||||
private void Run()
|
||||
{
|
||||
Debug.WriteLine("AsyncBoundObject Run execution.");
|
||||
}
|
||||
|
||||
public string Hello(string name)
|
||||
{
|
||||
return "Hello " + name;
|
||||
|
||||
@@ -61,6 +61,20 @@
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("Async call (Div with Blocking Task 16 / 2):", function (assert)
|
||||
{
|
||||
var asyncCallback = assert.async();
|
||||
|
||||
boundAsync.divWithBlockingTaskCall(16, 2).then(function (actualResult)
|
||||
{
|
||||
const expectedResult = 8
|
||||
|
||||
assert.equal(expectedResult, actualResult, "Divide 16 / 2 resulted in " + expectedResult);
|
||||
|
||||
asyncCallback();
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("Async call (Divide 16 /0)", function (assert)
|
||||
{
|
||||
var asyncCallback = assert.async();
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace CefSharp.Internals
|
||||
{
|
||||
//Limit to 1 task per methodRunnerQueue
|
||||
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/d0bcb415-fb1e-42e4-90f8-c43a088537fb/aborting-a-long-running-task-in-tpl?forum=parallelextensions
|
||||
private readonly TaskFactory methodRunnerQueueTaskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(1));
|
||||
private readonly LimitedConcurrencyLevelTaskScheduler taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
|
||||
private readonly JavascriptObjectRepository repository;
|
||||
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace CefSharp.Internals
|
||||
|
||||
public void Enqueue(MethodInvocation methodInvocation)
|
||||
{
|
||||
methodRunnerQueueTaskFactory.StartNew(() =>
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var result = ExecuteMethodInvocation(methodInvocation);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace CefSharp.Internals
|
||||
{
|
||||
handler(this, new MethodInvocationCompleteArgs(result));
|
||||
}
|
||||
}, cancellationTokenSource.Token);
|
||||
}, cancellationTokenSource.Token, TaskCreationOptions.HideScheduler, taskScheduler);
|
||||
}
|
||||
|
||||
private MethodInvocationResult ExecuteMethodInvocation(MethodInvocation methodInvocation)
|
||||
|
||||
Reference in New Issue
Block a user