@@ -1091,16 +1091,15 @@ private async Task QueryResultsAsync(bool isReQuery = false, bool reSelect = tru
1091
1091
1092
1092
var currentUpdateSource = new CancellationTokenSource ( ) ;
1093
1093
_updateSource = currentUpdateSource ;
1094
- var currentCancellationToken = _updateSource . Token ;
1095
- _updateToken = currentCancellationToken ;
1094
+ _updateToken = _updateSource . Token ;
1096
1095
1097
1096
ProgressBarVisibility = Visibility . Hidden ;
1098
1097
_isQueryRunning = true ;
1099
1098
1100
1099
// Switch to ThreadPool thread
1101
1100
await TaskScheduler . Default ;
1102
1101
1103
- if ( currentCancellationToken . IsCancellationRequested )
1102
+ if ( _updateSource . Token . IsCancellationRequested )
1104
1103
return ;
1105
1104
1106
1105
// Update the query's IsReQuery property to true if this is a re-query
@@ -1126,24 +1125,23 @@ private async Task QueryResultsAsync(bool isReQuery = false, bool reSelect = tru
1126
1125
SearchIconVisibility = Visibility . Visible ;
1127
1126
}
1128
1127
1129
-
1130
1128
if ( query . ActionKeyword == Plugin . Query . GlobalPluginWildcardSign )
1131
1129
{
1132
1130
// Wait 45 millisecond for query change in global query
1133
1131
// if query changes, return so that it won't be calculated
1134
- await Task . Delay ( 45 , currentCancellationToken ) ;
1135
- if ( currentCancellationToken . IsCancellationRequested )
1132
+ await Task . Delay ( 45 , _updateSource . Token ) ;
1133
+ if ( _updateSource . Token . IsCancellationRequested )
1136
1134
return ;
1137
1135
}
1138
1136
1139
- _ = Task . Delay ( 200 , currentCancellationToken ) . ContinueWith ( _ =>
1137
+ _ = Task . Delay ( 200 , _updateSource . Token ) . ContinueWith ( _ =>
1140
1138
{
1141
1139
// start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
1142
- if ( ! currentCancellationToken . IsCancellationRequested && _isQueryRunning )
1140
+ if ( ! _updateSource . Token . IsCancellationRequested && _isQueryRunning )
1143
1141
{
1144
1142
ProgressBarVisibility = Visibility . Visible ;
1145
1143
}
1146
- } , currentCancellationToken , TaskContinuationOptions . NotOnCanceled , TaskScheduler . Default ) ;
1144
+ } , _updateSource . Token , TaskContinuationOptions . NotOnCanceled , TaskScheduler . Default ) ;
1147
1145
1148
1146
// plugins is ICollection, meaning LINQ will get the Count and preallocate Array
1149
1147
@@ -1153,7 +1151,6 @@ private async Task QueryResultsAsync(bool isReQuery = false, bool reSelect = tru
1153
1151
true => Task . CompletedTask
1154
1152
} ) . ToArray ( ) ;
1155
1153
1156
-
1157
1154
try
1158
1155
{
1159
1156
// Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
@@ -1164,13 +1161,13 @@ private async Task QueryResultsAsync(bool isReQuery = false, bool reSelect = tru
1164
1161
// nothing to do here
1165
1162
}
1166
1163
1167
- if ( currentCancellationToken . IsCancellationRequested )
1164
+ if ( _updateSource . Token . IsCancellationRequested )
1168
1165
return ;
1169
1166
1170
1167
// this should happen once after all queries are done so progress bar should continue
1171
1168
// until the end of all querying
1172
1169
_isQueryRunning = false ;
1173
- if ( ! currentCancellationToken . IsCancellationRequested )
1170
+ if ( ! _updateSource . Token . IsCancellationRequested )
1174
1171
{
1175
1172
// update to hidden if this is still the current query
1176
1173
ProgressBarVisibility = Visibility . Hidden ;
@@ -1184,9 +1181,9 @@ async Task QueryTaskAsync(PluginPair plugin, bool reSelect = true)
1184
1181
await Task . Yield ( ) ;
1185
1182
1186
1183
IReadOnlyList < Result > results =
1187
- await PluginManager . QueryForPluginAsync ( plugin , query , currentCancellationToken ) ;
1184
+ await PluginManager . QueryForPluginAsync ( plugin , query , _updateSource . Token ) ;
1188
1185
1189
- currentCancellationToken . ThrowIfCancellationRequested ( ) ;
1186
+ _updateSource . Token . ThrowIfCancellationRequested ( ) ;
1190
1187
1191
1188
IReadOnlyList < Result > resultsCopy ;
1192
1189
if ( results == null )
@@ -1200,7 +1197,7 @@ async Task QueryTaskAsync(PluginPair plugin, bool reSelect = true)
1200
1197
}
1201
1198
1202
1199
if ( ! _resultsUpdateChannelWriter . TryWrite ( new ResultsForUpdate ( resultsCopy , plugin . Metadata , query ,
1203
- currentCancellationToken , reSelect ) ) )
1200
+ _updateSource . Token , reSelect ) ) )
1204
1201
{
1205
1202
Log . Error ( "MainViewModel" , "Unable to add item to Result Update Queue" ) ;
1206
1203
}
0 commit comments