This repository was archived by the owner on Apr 21, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +20
-6
lines changed Expand file tree Collapse file tree 5 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ public static void Start()
56
56
_prevTimeApp = DateTime . Now ;
57
57
58
58
appQueue = new AsyncCollection < object > ( ) ;
59
-
59
+
60
+ SharedMessagePump . Initialize ( ) ;
60
61
Task . Factory . StartNew ( ( ) => { } ) . ContinueWith ( x =>
61
62
{
62
63
WindowHook . WindowCreated += new GeneralShellHookEventHandler ( WindowCreated ) ;
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ public static void Start()
46
46
{
47
47
_clipQueue = new AsyncCollection < object > ( ) ;
48
48
49
+ SharedMessagePump . Initialize ( ) ;
49
50
Task . Factory . StartNew ( ( ) => { } ) . ContinueWith ( x =>
50
51
{
51
52
_clip = new ClipBoardHook ( ) ;
Original file line number Diff line number Diff line change @@ -14,14 +14,18 @@ internal class SharedMessagePump
14
14
{
15
15
static Lazy < TaskScheduler > _scheduler ;
16
16
static Lazy < MessageHandler > _messageHandler ;
17
-
17
+
18
18
static SharedMessagePump ( )
19
19
{
20
20
_scheduler = new Lazy < TaskScheduler > ( ( ) =>
21
21
{
22
-
23
- if ( SynchronizationContext . Current != null )
24
- return TaskScheduler . FromCurrentSynchronizationContext ( ) ;
22
+ Dispatcher dispatcher = Dispatcher . FromThread ( Thread . CurrentThread ) ;
23
+ if ( dispatcher != null )
24
+ {
25
+ if ( SynchronizationContext . Current != null )
26
+ return TaskScheduler . FromCurrentSynchronizationContext ( ) ;
27
+ }
28
+
25
29
26
30
TaskScheduler current = null ;
27
31
@@ -66,6 +70,12 @@ static SharedMessagePump()
66
70
} ) ;
67
71
}
68
72
73
+ internal static void Initialize ( )
74
+ {
75
+ GetTaskScheduler ( ) ;
76
+ GetHandle ( ) ;
77
+ }
78
+
69
79
internal static TaskScheduler GetTaskScheduler ( )
70
80
{
71
81
return _scheduler . Value ;
Original file line number Diff line number Diff line change @@ -48,7 +48,8 @@ public static void Start()
48
48
_kh = new KeyboardHook ( ) ;
49
49
_kh . KeyDown += new RawKeyEventHandler ( KListener ) ;
50
50
_kh . KeyUp += new RawKeyEventHandler ( KListener ) ;
51
- var handle = SharedMessagePump . GetHandle ( ) ;
51
+
52
+ SharedMessagePump . Initialize ( ) ;
52
53
Task . Factory . StartNew ( ( ) => { } ) . ContinueWith ( x =>
53
54
{
54
55
_kh . Start ( ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ public static void Start()
36
36
_mh = new MouseHook ( ) ;
37
37
_mh . MouseAction += MListener ;
38
38
39
+ SharedMessagePump . Initialize ( ) ;
39
40
Task . Factory . StartNew ( ( ) => { } ) . ContinueWith ( x =>
40
41
{
41
42
_mh . Start ( ) ;
You can’t perform that action at this time.
0 commit comments