From a95a91e6cdd3908f689e11951a80e7e81d4b2cf1 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 28 Oct 2023 19:58:53 -0600 Subject: [PATCH] feat: set ConfigureAwait(false) on the delegate task --- src/Prism.Core/Commands/AsyncDelegateCommand.cs | 10 ++++++---- src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs | 11 +++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Prism.Core/Commands/AsyncDelegateCommand.cs b/src/Prism.Core/Commands/AsyncDelegateCommand.cs index c85e400659..7781457969 100644 --- a/src/Prism.Core/Commands/AsyncDelegateCommand.cs +++ b/src/Prism.Core/Commands/AsyncDelegateCommand.cs @@ -1,4 +1,4 @@ -using System.Linq.Expressions; +using System.Linq.Expressions; using System; using System.Threading; using System.Threading.Tasks; @@ -86,17 +86,19 @@ public bool IsExecuting /// /// Executes the command. /// - public async Task Execute(CancellationToken cancellationToken = default) + public async Task Execute(CancellationToken? cancellationToken) { + var token = cancellationToken ?? _getCancellationToken(); try { if (!_enableParallelExecution && IsExecuting) return; IsExecuting = true; - await _executeMethod(cancellationToken); + await _executeMethod(token) + .ConfigureAwait(false); } - catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested) + catch (TaskCanceledException) when (token.IsCancellationRequested) { // Do nothing... the Task was cancelled } diff --git a/src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs b/src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs index 2c6f573e2f..4f367471f8 100644 --- a/src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs +++ b/src/Prism.Core/Commands/AsyncDelegateCommand{T}.cs @@ -1,4 +1,4 @@ -using System.Linq.Expressions; +using System.Linq.Expressions; using System; using System.Threading; using System.Threading.Tasks; @@ -88,17 +88,20 @@ public bool IsExecuting /// /// Executes the command. /// - public async Task Execute(T parameter, CancellationToken cancellationToken = default) + public async Task Execute(T parameter, CancellationToken? cancellationToken) { + var token = cancellationToken ?? _getCancellationToken(); + try { if (!_enableParallelExecution && IsExecuting) return; IsExecuting = true; - await _executeMethod(parameter, cancellationToken); + await _executeMethod(parameter, token) + .ConfigureAwait(false); } - catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested) + catch (TaskCanceledException) when (token.IsCancellationRequested) { // Do nothing... the Task was cancelled }