Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DispatcherService.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 using System.Windows.Threading;
6 
7 using SiliconStudio.Presentation.Services;
8 
9 namespace SiliconStudio.Presentation.View
10 {
12  {
13  private readonly Dispatcher dispatcher;
14 
15  public static DispatcherService Create()
16  {
17  return new DispatcherService(Dispatcher.CurrentDispatcher);
18  }
19 
20  public DispatcherService(Dispatcher dispatcher)
21  {
22  if (dispatcher == null) throw new ArgumentNullException("dispatcher");
23  this.dispatcher = dispatcher;
24  }
25 
26  public void Invoke(Action callback)
27  {
28  dispatcher.Invoke(callback);
29  }
30 
31  public TResult Invoke<TResult>(Func<TResult> callback)
32  {
33  return dispatcher.Invoke(callback);
34  }
35 
36  public Action Invoked(Action callback)
37  {
38  return () => dispatcher.Invoke(callback);
39  }
40 
41  public Task InvokeAsync(Action callback)
42  {
43  return dispatcher.InvokeAsync(callback).Task;
44  }
45 
46  public Task<TResult> InvokeAsync<TResult>(Func<TResult> callback)
47  {
48  return dispatcher.InvokeAsync(callback).Task;
49  }
50  }
51 }