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
}