@@ -12,7 +12,10 @@ public class MacroScript
12
12
public async Task Delay ( int millsecond )
13
13
{
14
14
try {
15
- await Task . Delay ( millsecond ) ;
15
+ await Task . Delay ( millsecond , AppEnvironment . GetInstance ( ) . CancelToken ) ;
16
+ }
17
+ catch ( TaskCanceledException ) {
18
+ throw ;
16
19
}
17
20
catch ( Exception ex ) {
18
21
await CommonUtil . HandleExceptionAsync ( ex ) ;
@@ -29,6 +32,9 @@ public async Task PressKey( ushort virtualKey )
29
32
30
33
await SendKeyInput ( input . ToArray ( ) ) ;
31
34
}
35
+ catch ( TaskCanceledException ) {
36
+ throw ;
37
+ }
32
38
catch ( Exception ex ) {
33
39
await CommonUtil . HandleExceptionAsync ( ex ) ;
34
40
}
@@ -44,6 +50,9 @@ public async Task ReleaseKey( ushort virtualKey )
44
50
45
51
await SendKeyInput ( input . ToArray ( ) ) ;
46
52
}
53
+ catch ( TaskCanceledException ) {
54
+ throw ;
55
+ }
47
56
catch ( Exception ex ) {
48
57
await CommonUtil . HandleExceptionAsync ( ex ) ;
49
58
}
@@ -54,6 +63,9 @@ public async Task SetMousePos( int x, int y )
54
63
try {
55
64
await GetSingleMouseEventTask ( x , y , MouseEvent . Move ) ;
56
65
}
66
+ catch ( TaskCanceledException ) {
67
+ throw ;
68
+ }
57
69
catch ( Exception ex ) {
58
70
await CommonUtil . HandleExceptionAsync ( ex ) ;
59
71
}
@@ -64,6 +76,9 @@ public async Task PushLeftButton( int x, int y )
64
76
try {
65
77
await GetSingleMouseEventTask ( x , y , MouseEvent . LeftDown ) ;
66
78
}
79
+ catch ( TaskCanceledException ) {
80
+ throw ;
81
+ }
67
82
catch ( Exception ex ) {
68
83
await CommonUtil . HandleExceptionAsync ( ex ) ;
69
84
}
@@ -74,6 +89,9 @@ public async Task PullLeftButton( int x, int y )
74
89
try {
75
90
await GetSingleMouseEventTask ( x , y , MouseEvent . LeftUp ) ;
76
91
}
92
+ catch ( TaskCanceledException ) {
93
+ throw ;
94
+ }
77
95
catch ( Exception ex ) {
78
96
await CommonUtil . HandleExceptionAsync ( ex ) ;
79
97
}
@@ -84,6 +102,9 @@ public async Task PushMiddleButton( int x, int y )
84
102
try {
85
103
await GetSingleMouseEventTask ( x , y , MouseEvent . MiddleDown ) ;
86
104
}
105
+ catch ( TaskCanceledException ) {
106
+ throw ;
107
+ }
87
108
catch ( Exception ex ) {
88
109
await CommonUtil . HandleExceptionAsync ( ex ) ;
89
110
}
@@ -94,6 +115,9 @@ public async Task PullMiddleButton( int x, int y )
94
115
try {
95
116
await GetSingleMouseEventTask ( x , y , MouseEvent . MiddleUp ) ;
96
117
}
118
+ catch ( TaskCanceledException ) {
119
+ throw ;
120
+ }
97
121
catch ( Exception ex ) {
98
122
await CommonUtil . HandleExceptionAsync ( ex ) ;
99
123
}
@@ -104,6 +128,9 @@ public async Task PushRightButton( int x, int y )
104
128
try {
105
129
await GetSingleMouseEventTask ( x , y , MouseEvent . RightDown ) ;
106
130
}
131
+ catch ( TaskCanceledException ) {
132
+ throw ;
133
+ }
107
134
catch ( Exception ex ) {
108
135
await CommonUtil . HandleExceptionAsync ( ex ) ;
109
136
}
@@ -114,6 +141,9 @@ public async Task PullRightButton( int x, int y )
114
141
try {
115
142
await GetSingleMouseEventTask ( x , y , MouseEvent . RightUp ) ;
116
143
}
144
+ catch ( TaskCanceledException ) {
145
+ throw ;
146
+ }
117
147
catch ( Exception ex ) {
118
148
await CommonUtil . HandleExceptionAsync ( ex ) ;
119
149
}
@@ -129,6 +159,9 @@ public async Task WheelMouse( int x, int y, int wheelRotate )
129
159
130
160
await SendMouseInput ( input . ToArray ( ) ) ;
131
161
}
162
+ catch ( TaskCanceledException ) {
163
+ throw ;
164
+ }
132
165
catch ( Exception ex ) {
133
166
await CommonUtil . HandleExceptionAsync ( ex ) ;
134
167
}
@@ -144,6 +177,9 @@ public async Task HWheelMouse( int x, int y, int wheelRotate )
144
177
145
178
await SendMouseInput ( input . ToArray ( ) ) ;
146
179
}
180
+ catch ( TaskCanceledException ) {
181
+ throw ;
182
+ }
147
183
catch ( Exception ex ) {
148
184
await CommonUtil . HandleExceptionAsync ( ex ) ;
149
185
}
@@ -152,10 +188,12 @@ public async Task HWheelMouse( int x, int y, int wheelRotate )
152
188
public async Task SetMode ( byte mode )
153
189
{
154
190
try {
155
- await Task . Run ( ( ) =>
156
- {
191
+ await Task . Run ( ( ) => {
157
192
AppEnvironment . GetInstance ( ) . Mode = ( ModeKind ) mode ;
158
- } ) ;
193
+ } , AppEnvironment . GetInstance ( ) . CancelToken ) ;
194
+ }
195
+ catch ( TaskCanceledException ) {
196
+ throw ;
159
197
}
160
198
catch ( Exception ex ) {
161
199
await CommonUtil . HandleExceptionAsync ( ex ) ;
@@ -165,7 +203,10 @@ await Task.Run( () =>
165
203
public async Task WrileUserCustomLog ( Dictionary < string , string > userCustomDic )
166
204
{
167
205
try {
168
- await Logger . WriteUserCustomAsync ( userCustomDic ) ;
206
+ await Task . Run ( ( ) => Logger . WriteUserCustomAsync ( userCustomDic ) , AppEnvironment . GetInstance ( ) . CancelToken ) ;
207
+ }
208
+ catch ( TaskCanceledException ) {
209
+ throw ;
169
210
}
170
211
catch ( Exception ex ) {
171
212
await CommonUtil . HandleExceptionAsync ( ex ) ;
@@ -233,7 +274,7 @@ private async Task SendMouseInput( MouseInput[] mouseInput )
233
274
}
234
275
235
276
if ( ! CommonUtil . CheckMode ( ModeKind . KeyOnly ) ) {
236
- await Task . Run ( ( ) => SendInputWrapper . SendMouseInput ( mouseInput ) ) ;
277
+ await Task . Run ( ( ) => SendInputWrapper . SendMouseInput ( mouseInput ) , AppEnvironment . GetInstance ( ) . CancelToken ) ;
237
278
}
238
279
}
239
280
@@ -244,7 +285,7 @@ private async Task SendKeyInput( KeyInput[] keyInput )
244
285
}
245
286
246
287
if ( ! CommonUtil . CheckMode ( ModeKind . MouseOnly ) ) {
247
- await Task . Run ( ( ) => SendInputWrapper . SendKeyInput ( keyInput ) ) ;
288
+ await Task . Run ( ( ) => SendInputWrapper . SendKeyInput ( keyInput ) , AppEnvironment . GetInstance ( ) . CancelToken ) ;
248
289
}
249
290
}
250
291
}
0 commit comments