mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use task.run in addresult instead of CollectionChange event.
This commit is contained in:
parent
25bc2a70e3
commit
eb13a18d52
1 changed files with 28 additions and 17 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue