Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AsyncCommand.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Threading.Tasks;
5 
6 using SiliconStudio.Presentation.ViewModel;
7 
8 namespace SiliconStudio.Presentation.Commands
9 {
10  public class AsyncCommand : CommandBase
11  {
12  private readonly Action<object> action;
13 
14  public AsyncCommand(IViewModelServiceProvider serviceProvider, Action<object> action)
15  : base(serviceProvider)
16  {
17  this.action = action;
18  }
19 
20  public AsyncCommand(IViewModelServiceProvider serviceProvider, Action action)
21  : base(serviceProvider)
22  {
23  this.action = x => action();
24  }
25 
26  public override void Execute(object parameter)
27  {
28  Task.Run(() => action(parameter));
29  }
30 
31  public async Task ExecuteAwaitable(object parameter = null)
32  {
33  await Task.Run(() => action(parameter));
34  }
35  }
36 }
async Task ExecuteAwaitable(object parameter=null)
Definition: AsyncCommand.cs:31
override void Execute(object parameter)
Definition: AsyncCommand.cs:26
AsyncCommand(IViewModelServiceProvider serviceProvider, Action< object > action)
Definition: AsyncCommand.cs:14
An abstract class that is the base implementation of the ICommandBase interface.
Definition: CommandBase.cs:13
AsyncCommand(IViewModelServiceProvider serviceProvider, Action action)
Definition: AsyncCommand.cs:20