forked from ARDrone2Windows/SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartDispatcher.cs
45 lines (44 loc) · 1 KB
/
SmartDispatcher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
#if WINDOWS_PHONE
using System.Windows.Threading;
#else
using Windows.UI.Core;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
#endif
namespace ARDrone2Client.Common
{
public static class SmartDispatcher
{
#if !WINDOWS_PHONE
private static CoreDispatcher _Dispatcher;
public static CoreDispatcher Dispatcher
{
get
{
return _Dispatcher;
}
set
{
_Dispatcher = value;
}
}
#endif
public static void Invoke(Action action)
{
#if WINDOWS_PHONE
//SynchronizationContext.Current.Post()
#else
if (_Dispatcher != null && !_Dispatcher.HasThreadAccess)
{
IAsyncAction asyncAction = _Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(action));
}
else
{
action();
}
#endif
}
}
}