diff --git a/src/System.Waf/System.Waf/System.Waf.Core.Test/Applications/AsyncDelegateCommandTest.cs b/src/System.Waf/System.Waf/System.Waf.Core.Test/Applications/AsyncDelegateCommandTest.cs index c85d705e..8253f836 100644 --- a/src/System.Waf/System.Waf/System.Waf.Core.Test/Applications/AsyncDelegateCommandTest.cs +++ b/src/System.Waf/System.Waf/System.Waf.Core.Test/Applications/AsyncDelegateCommandTest.cs @@ -10,7 +10,7 @@ namespace Test.Waf.Applications public class AsyncDelegateCommandTest { [TestMethod] - public void CanExecuteDuringAsyncExecute() + public async Task CanExecuteDuringAsyncExecute() { AssertHelper.ExpectedException<ArgumentNullException>(() => new AsyncDelegateCommand((Func<Task>)null!)); @@ -24,14 +24,16 @@ public void CanExecuteDuringAsyncExecute() }); Assert.IsTrue(command.CanExecute(null)); - command.Execute(null); + var task = command.ExecuteAsync(null); executeCalled = false; Assert.IsFalse(command.CanExecute(null)); - command.Execute(null); + command.Execute(null); // second call will be ignored Assert.IsFalse(executeCalled); + Assert.IsFalse(task.IsCompleted); tcs.SetResult(null); + await task; Assert.IsTrue(command.CanExecute(null)); command.Execute(null); Assert.IsTrue(executeCalled); diff --git a/src/System.Waf/System.Waf/System.Waf.Core/Applications/AsyncDelegateCommand.cs b/src/System.Waf/System.Waf/System.Waf.Core/Applications/AsyncDelegateCommand.cs index 5561528c..23b20aa9 100644 --- a/src/System.Waf/System.Waf/System.Waf.Core/Applications/AsyncDelegateCommand.cs +++ b/src/System.Waf/System.Waf/System.Waf.Core/Applications/AsyncDelegateCommand.cs @@ -68,10 +68,15 @@ private bool IsExecuting public bool CanExecute(object? parameter) => !IsExecuting && (canExecute == null || canExecute(parameter)); /// <inheritdoc /> - public async void Execute(object? parameter) + public void Execute(object? parameter) => _ = ExecuteAsync(parameter); + + /// <summary>Defines the method to be called when the command is invoked.</summary> + /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to null.</param> + /// <returns>A task that represents an asynchronous operation.</returns> + public async Task ExecuteAsync(object? parameter) { if (!CanExecute(parameter)) return; - + IsExecuting = true; try { diff --git a/src/System.Waf/System.Waf/System.Waf.Core/GlobalSuppressions.cs b/src/System.Waf/System.Waf/System.Waf.Core/GlobalSuppressions.cs index d2500e8c..c4ecc870 100644 --- a/src/System.Waf/System.Waf/System.Waf.Core/GlobalSuppressions.cs +++ b/src/System.Waf/System.Waf/System.Waf.Core/GlobalSuppressions.cs @@ -42,3 +42,4 @@ [assembly: SuppressMessage("Security", "CA2109:Review visible event handlers", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Foundation.ObservableListViewBase`1.OnCollectionItemChanged(System.Object,System.ComponentModel.PropertyChangedEventArgs)")] [assembly: SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Presentation.Services.SettingsService.Dispose(System.Boolean)")] [assembly: SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Applications.IDelegateCommand.RaiseCanExecuteChanged")] +[assembly: SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Applications.DelegateCommand.RaiseCanExecuteChanged(System.Waf.Applications.IDelegateCommand[])")]