File tree Expand file tree Collapse file tree 1 file changed +27
-23
lines changed
Project-Aurora/AuroraCommon/Utils Expand file tree Collapse file tree 1 file changed +27
-23
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ private Thread CreateThread()
73
73
_semaphore . Wait ( CancelToken . Token ) ;
74
74
ThreadCallback ( ) ;
75
75
}
76
+ catch ( OperationCanceledException )
77
+ {
78
+ // end the thread
79
+ }
76
80
finally
77
81
{
78
82
_semaphore . Release ( ) ;
@@ -86,35 +90,35 @@ private Thread CreateThread()
86
90
thread . Start ( ) ;
87
91
Thread . Yield ( ) ;
88
92
return thread ;
89
-
90
- void ThreadCallback ( ) {
91
- if ( _handles . Length <= 1 )
93
+ }
94
+
95
+ private void ThreadCallback ( ) {
96
+ if ( _handles . Length <= 1 )
97
+ {
98
+ // stop thread if only handle is cancel token
99
+ return ;
100
+ }
101
+ while ( true )
102
+ {
103
+ if ( CancelToken . IsCancellationRequested )
92
104
{
93
- // stop thread if only handle is cancel token
94
105
return ;
95
106
}
96
- while ( true )
107
+ var i = WaitHandle . WaitAny ( _handles ) ;
108
+ switch ( i )
97
109
{
98
- if ( CancelToken . IsCancellationRequested )
99
- {
110
+ case 0 :
100
111
return ;
101
- }
102
- var i = WaitHandle . WaitAny ( _handles ) ;
103
- switch ( i )
104
- {
105
- case 0 :
106
- return ;
107
- default :
108
- if ( i >= _handles . Length )
109
- {
110
- break ;
111
- }
112
- Task . Run ( ( ) =>
113
- {
114
- _actions [ i ] . Invoke ( ) ;
115
- } ) ;
112
+ default :
113
+ if ( i >= _handles . Length )
114
+ {
116
115
break ;
117
- }
116
+ }
117
+ Task . Run ( ( ) =>
118
+ {
119
+ _actions [ i ] . Invoke ( ) ;
120
+ } ) ;
121
+ break ;
118
122
}
119
123
}
120
124
}
You can’t perform that action at this time.
0 commit comments