-
-
Save NickStrupat/939cf839b32fb0e36eba to your computer and use it in GitHub Desktop.
Revisions
-
NickStrupat revised this gist
May 3, 2016 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,17 +3,17 @@ using System.Threading.Tasks; using System.Windows.Input; class AsyncCommand : ICommand { public Boolean CanExecute(Object parameter = null) => !IsRunning; public event EventHandler CanExecuteChanged = delegate { }; public async void Execute(Object parameter = null) { IsRunning = true; try { await asyncAction(); } finally { IsRunning = false; } } @@ -23,13 +23,13 @@ class AsyncCommand : ICommand { this.asyncAction = asyncAction; } private Boolean isRunning; private Boolean IsRunning { get { return isRunning; } set { isRunning = value; CanExecuteChanged.Invoke(this, EventArgs.Empty); } } -
NickStrupat revised this gist
May 3, 2016 . 1 changed file with 31 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,37 +1,36 @@ using System; using System.Threading.Tasks; using System.Windows.Input; class AsyncCommand : ICommand { public Boolean CanExecute(Object parameter = null) => !isRunning; public event EventHandler CanExecuteChanged = delegate { }; public async void Execute(Object parameter = null) { isRunning = true; try { await asyncAction(); } finally { isRunning = false; } } private readonly Func<Task> asyncAction; public AsyncCommand(Func<Task> asyncAction) { this.asyncAction = asyncAction; } private Boolean isRunningField; private Boolean isRunning { get { return isRunningField; } set { isRunningField = value; CanExecuteChanged.Invoke(this, EventArgs.Empty); } } } -
rossdargan created this gist
Nov 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ class AsyncCommand : ICommand { private readonly Func<Task> asyncAction; private bool isRunning = false; public bool IsRunning { get { return isRunning; } set { isRunning = value; if (CanExecuteChanged != null) { CanExecuteChanged(this, EventArgs.Empty); } } } public AsyncCommand(Func<Task> asyncAction) { this.asyncAction = asyncAction; } public bool CanExecute(object parameter) { return !isRunning; } public event EventHandler CanExecuteChanged; public async void Execute(object parameter) { IsRunning = true; await asyncAction(); IsRunning = false; } }