use sync context for invokeasync
This commit is contained in:
@@ -37,6 +37,43 @@ public static class NodeExtensions
|
|||||||
extension(Node node)
|
extension(Node node)
|
||||||
{
|
{
|
||||||
public Task InvokeAsync(Action workItem)
|
public Task InvokeAsync(Action workItem)
|
||||||
|
{
|
||||||
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
|
//WorkerThreadPool.AddTask();
|
||||||
|
Dispatcher.SynchronizationContext.Post(_ =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
workItem();
|
||||||
|
taskCompletionSource.SetResult();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
taskCompletionSource.SetException(ex);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
return taskCompletionSource.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task InvokeAsync(Func<Task> workItem)
|
||||||
|
{
|
||||||
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
|
Dispatcher.SynchronizationContext.Post(async void (_) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await workItem();
|
||||||
|
taskCompletionSource.SetResult();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
taskCompletionSource.SetException(ex);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
return taskCompletionSource.Task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task InvokeDeferredAsync(Action workItem)
|
||||||
{
|
{
|
||||||
var taskCompletionSource = new TaskCompletionSource();
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
//WorkerThreadPool.AddTask();
|
//WorkerThreadPool.AddTask();
|
||||||
@@ -55,7 +92,7 @@ public static class NodeExtensions
|
|||||||
return taskCompletionSource.Task;
|
return taskCompletionSource.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task InvokeAsync(Func<Task> workItem)
|
public Task InvokeDeferredAsync(Func<Task> workItem)
|
||||||
{
|
{
|
||||||
var taskCompletionSource = new TaskCompletionSource();
|
var taskCompletionSource = new TaskCompletionSource();
|
||||||
//WorkerThreadPool.AddTask();
|
//WorkerThreadPool.AddTask();
|
||||||
|
|||||||
Reference in New Issue
Block a user