Created
September 16, 2013 15:08
-
-
Save daanl/6581925 to your computer and use it in GitHub Desktop.
This file contains 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 characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var command = new AsyncRelayCommand( | |
async () => | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(1)); | |
Console.WriteLine("hi"); | |
}); | |
Console.WriteLine("before"); | |
command.Execute(null); | |
Console.WriteLine("after"); | |
Console.Read(); | |
} | |
} | |
public class AsyncRelayCommand : ICommand | |
{ | |
private readonly Func<Task> _action; | |
public AsyncRelayCommand(Func<Task> action) | |
{ | |
_action = action; | |
} | |
public bool CanExecute(object parameter) | |
{ | |
return true; | |
} | |
public void Execute(object parameter) | |
{ | |
_action().Wait(); | |
} | |
public event EventHandler CanExecuteChanged; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment