Skip to content

Instantly share code, notes, and snippets.

@daanl
Created September 16, 2013 15:08
Show Gist options
  • Save daanl/6581925 to your computer and use it in GitHub Desktop.
Save daanl/6581925 to your computer and use it in GitHub Desktop.
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