Use task.run in addresult instead of CollectionChange event.

This commit is contained in:
弘韬 张 2020-12-03 15:38:00 +08:00
parent 25bc2a70e3
commit eb13a18d52

View file

@ -150,11 +150,20 @@ namespace Flow.Launcher.ViewModel
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
// fix selected index flow
var updateTask = Task.Run(() =>
{
// update UI in one run, so it can avoid UI flickering
Results.Update(newResults);
if (Results.Any())
SelectedItem = Results[0];
});
if (!updateTask.Wait(300))
{
updateTask.Dispose();
throw new TimeoutException("Update result use too much time.");
}
// update UI in one run, so it can avoid UI flickering
Results.Update(newResults);
if (Results.Any())
SelectedItem = Results[0];
}
if (Visbility != Visibility.Visible && Results.Count > 0)
@ -179,14 +188,23 @@ namespace Flow.Launcher.ViewModel
return;
lock (_collectionLock)
{
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
// fix selected index flow
var updateTask = Task.Run(() =>
{
// update UI in one run, so it can avoid UI flickering
Results.Update(newResults, token);
if (Results.Any())
SelectedItem = Results[0];
});
if (!updateTask.Wait(300))
{
updateTask.Dispose();
throw new TimeoutException("Update result use too much time.");
}
Results.Update(newResults, token);
if (token.IsCancellationRequested)
return;
if (Results.Any())
SelectedItem = Results[0];
}
switch (Visbility)
@ -282,14 +300,7 @@ namespace Flow.Launcher.ViewModel
{
if (!_suppressNotifying)
{
var notifyChangeTask = Task.Run(() => base.OnCollectionChanged(e));
if (notifyChangeTask.Wait(300))
return;
else
{
notifyChangeTask.Dispose();
throw new TimeoutException();
}
base.OnCollectionChanged(e);
}
}