mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[PTRun]Integrated lock mechanism for thread-safe Results updates. (#26104)
This commit is contained in:
@@ -606,14 +606,17 @@ namespace PowerLauncher
|
|||||||
|
|
||||||
private void ClearResults()
|
private void ClearResults()
|
||||||
{
|
{
|
||||||
_viewModel.Results.SelectedItem = null;
|
MainViewModel.PerformSafeAction(() =>
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
|
_viewModel.Results.SelectedItem = null;
|
||||||
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
{
|
{
|
||||||
_viewModel.Results.Clear();
|
Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
|
||||||
_viewModel.Results.Results.NotifyChanges();
|
{
|
||||||
}));
|
_viewModel.Results.Clear();
|
||||||
|
_viewModel.Results.Results.NotifyChanges();
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
private readonly PowerToysRunSettings _settings;
|
private readonly PowerToysRunSettings _settings;
|
||||||
private readonly QueryHistory _history;
|
private readonly QueryHistory _history;
|
||||||
private readonly UserSelectedRecord _userSelectedRecord;
|
private readonly UserSelectedRecord _userSelectedRecord;
|
||||||
private readonly object _addResultsLock = new object();
|
private static readonly object _addResultsLock = new object();
|
||||||
private readonly System.Diagnostics.Stopwatch _hotkeyTimer = new System.Diagnostics.Stopwatch();
|
private readonly System.Diagnostics.Stopwatch _hotkeyTimer = new System.Diagnostics.Stopwatch();
|
||||||
|
|
||||||
private string _queryTextBeforeLeaveResults;
|
private string _queryTextBeforeLeaveResults;
|
||||||
@@ -736,27 +736,30 @@ namespace PowerLauncher.ViewModel
|
|||||||
{
|
{
|
||||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
// Using CurrentCultureIgnoreCase since this is user facing
|
lock (_addResultsLock)
|
||||||
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
|
||||||
{
|
{
|
||||||
Results.Results.NotifyChanges();
|
// Using CurrentCultureIgnoreCase since this is user facing
|
||||||
}
|
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
|
||||||
if (Results.Results.Count > 0)
|
|
||||||
{
|
|
||||||
Results.Visibility = Visibility.Visible;
|
|
||||||
if (!isDelayedInvoke || noInitialResults)
|
|
||||||
{
|
{
|
||||||
Results.SelectedIndex = 0;
|
Results.Results.NotifyChanges();
|
||||||
if (noInitialResults)
|
}
|
||||||
|
|
||||||
|
if (Results.Results.Count > 0)
|
||||||
|
{
|
||||||
|
Results.Visibility = Visibility.Visible;
|
||||||
|
if (!isDelayedInvoke || noInitialResults)
|
||||||
{
|
{
|
||||||
Results.SelectedItem = Results.Results.FirstOrDefault();
|
Results.SelectedIndex = 0;
|
||||||
|
if (noInitialResults)
|
||||||
|
{
|
||||||
|
Results.SelectedItem = Results.Results.FirstOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
Results.Visibility = Visibility.Hidden;
|
||||||
Results.Visibility = Visibility.Hidden;
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -1217,5 +1220,13 @@ namespace PowerLauncher.ViewModel
|
|||||||
{
|
{
|
||||||
return _settings.SearchWaitForSlowResults;
|
return _settings.SearchWaitForSlowResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void PerformSafeAction(Action action)
|
||||||
|
{
|
||||||
|
lock (_addResultsLock)
|
||||||
|
{
|
||||||
|
action.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user