Add some cancellationtoken check

This commit is contained in:
弘韬 张 2020-11-16 19:20:52 +08:00
parent 71cac9cb23
commit 23d9e253ba
2 changed files with 17 additions and 17 deletions

View file

@ -698,16 +698,7 @@ namespace Flow.Launcher.ViewModel
{
if (!resultsForUpdates.Any())
return;
try
{
var token = resultsForUpdates.Select(r => r.Token).Distinct().Single();
}
catch (Exception e)
{
Log.Debug("Illegal token information");
}
CancellationToken token = resultsForUpdates.Select(r => r.Token).Distinct().Single();
foreach (var result in resultsForUpdates.SelectMany(u => u.Results))
@ -722,10 +713,10 @@ namespace Flow.Launcher.ViewModel
}
}
Results.AddResults(resultsForUpdates);
Results.AddResults(resultsForUpdates, token);
}
/// <summary>
/// <summary>U
/// To avoid deadlock, this method should not called from main thread
/// </summary>
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@ -136,7 +137,6 @@ namespace Flow.Launcher.ViewModel
public void AddResults(List<Result> newRawResults, string resultId)
{
var newResults = NewResults(newRawResults, resultId);
lock (_collectionLock)
{
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
@ -163,9 +163,11 @@ namespace Flow.Launcher.ViewModel
/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates)
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token)
{
var newResults = NewResults(resultsForUpdates);
if (token.IsCancellationRequested)
return;
lock (_collectionLock)
{
@ -173,7 +175,7 @@ namespace Flow.Launcher.ViewModel
// fix selected index flow
SelectedIndex = 0;
Results.Update(newResults);
Results.Update(newResults, token);
}
switch (Visbility)
@ -201,7 +203,7 @@ namespace Flow.Launcher.ViewModel
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings)).ToList();
return results.Where(r => r.Result.PluginID != resultId)
.Concat(results.Intersect(newResults).Union(newResults))
@ -292,10 +294,17 @@ namespace Flow.Launcher.ViewModel
/// Update the results collection with new results, try to keep identical results
/// </summary>
/// <param name="newItems"></param>
public void Update(List<ResultViewModel> newItems, CancellationToken token)
{
Clear();
if (token.IsCancellationRequested)
return;
AddRange(newItems);
}
public void Update(List<ResultViewModel> newItems)
{
Clear();
AddRange(newItems);
}
}