From bedccd2718c0b0f83a4fb5a0083771eadd99f7a1 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Thu, 27 Jan 2022 17:37:49 +1000 Subject: [PATCH] Async JavascriptBinding - Return null instead of empty object for async Task methods Resolves #3980 --- CefSharp/Internals/ConcurrentMethodRunnerQueue.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CefSharp/Internals/ConcurrentMethodRunnerQueue.cs b/CefSharp/Internals/ConcurrentMethodRunnerQueue.cs index 3f87b951de..5e957361b9 100644 --- a/CefSharp/Internals/ConcurrentMethodRunnerQueue.cs +++ b/CefSharp/Internals/ConcurrentMethodRunnerQueue.cs @@ -16,6 +16,7 @@ namespace CefSharp.Internals /// public class ConcurrentMethodRunnerQueue : IMethodRunnerQueue { + private static Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult"); private readonly IJavascriptObjectRepositoryInternal repository; private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); @@ -77,10 +78,14 @@ public void Enqueue(MethodInvocation methodInvocation) { if (t.Status == TaskStatus.RanToCompletion) { - //TODO: Use resultTask.GetAwaiter().GetResult() instead //We use some reflection to get the Result //If someone has a better way of doing this then please submit a PR result.Result = resultType.GetProperty("Result").GetValue(resultTask); + + if (result.Result != null && result.Result.GetType() == VoidTaskResultType) + { + result.Result = null; + } } else {