mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-06 03:07:54 +08:00
started update with cancellation token
This commit is contained in:
parent
bcc9379ebc
commit
dde03eca7c
@ -372,7 +372,7 @@ namespace Wox.ViewModel
|
|||||||
{
|
{
|
||||||
_updateSource?.Cancel();
|
_updateSource?.Cancel();
|
||||||
_updateSource = new CancellationTokenSource();
|
_updateSource = new CancellationTokenSource();
|
||||||
_updateToken = _updateSource.Token;
|
var updateToken = _updateSource.Token;
|
||||||
|
|
||||||
ProgressBarVisibility = Visibility.Hidden;
|
ProgressBarVisibility = Visibility.Hidden;
|
||||||
_queryHasReturn = false;
|
_queryHasReturn = false;
|
||||||
@ -402,18 +402,19 @@ namespace Wox.ViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lastQuery = query;
|
_lastQuery = query;
|
||||||
Task.Delay(200, _updateToken).ContinueWith(_ =>
|
Task.Delay(200, updateToken).ContinueWith(_ =>
|
||||||
{
|
{
|
||||||
if (query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
if (query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
||||||
{
|
{
|
||||||
ProgressBarVisibility = Visibility.Visible;
|
ProgressBarVisibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
}, _updateToken);
|
}, updateToken);
|
||||||
|
|
||||||
var plugins = PluginManager.ValidPluginsForQuery(query);
|
var plugins = PluginManager.ValidPluginsForQuery(query);
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
Parallel.ForEach(plugins, plugin =>
|
var parallelOptions = new ParallelOptions {CancellationToken = updateToken}; // so looping will stop once it was cancelled
|
||||||
|
Parallel.ForEach(plugins, parallelOptions, plugin =>
|
||||||
{
|
{
|
||||||
var config = _settings.PluginSettings.Plugins[plugin.Metadata.ID];
|
var config = _settings.PluginSettings.Plugins[plugin.Metadata.ID];
|
||||||
if (!config.Disabled)
|
if (!config.Disabled)
|
||||||
@ -421,13 +422,13 @@ namespace Wox.ViewModel
|
|||||||
var results = PluginManager.QueryForPlugin(plugin, query);
|
var results = PluginManager.QueryForPlugin(plugin, query);
|
||||||
UpdateResultView(results, plugin.Metadata, query);
|
UpdateResultView(results, plugin.Metadata, query);
|
||||||
}
|
}
|
||||||
});
|
});// TODO add cancel code.
|
||||||
|
|
||||||
// this should happen once after all queries are done so progress bar should continue
|
// this should happen once after all queries are done so progress bar should continue
|
||||||
// until the end of all querying
|
// until the end of all querying
|
||||||
_queryHasReturn = true;
|
_queryHasReturn = true;
|
||||||
ProgressBarVisibility = Visibility.Hidden;
|
ProgressBarVisibility = Visibility.Hidden;
|
||||||
}, _updateToken);
|
}, updateToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user