mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 05:06:36 +02:00
[PTRun]Integrated lock mechanism for thread-safe Results updates. (#26104)
This commit is contained in:
@@ -605,6 +605,8 @@ namespace PowerLauncher
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ClearResults()
|
private void ClearResults()
|
||||||
|
{
|
||||||
|
MainViewModel.PerformSafeAction(() =>
|
||||||
{
|
{
|
||||||
_viewModel.Results.SelectedItem = null;
|
_viewModel.Results.SelectedItem = null;
|
||||||
System.Threading.Tasks.Task.Run(() =>
|
System.Threading.Tasks.Task.Run(() =>
|
||||||
@@ -615,6 +617,7 @@ namespace PowerLauncher
|
|||||||
_viewModel.Results.Results.NotifyChanges();
|
_viewModel.Results.Results.NotifyChanges();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeselectAllResults()
|
private void DeselectAllResults()
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -735,6 +735,8 @@ namespace PowerLauncher.ViewModel
|
|||||||
private void UpdateResultsListViewAfterQuery(string queryText, bool noInitialResults = false, bool isDelayedInvoke = false)
|
private void UpdateResultsListViewAfterQuery(string queryText, bool noInitialResults = false, bool isDelayedInvoke = false)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
|
||||||
|
{
|
||||||
|
lock (_addResultsLock)
|
||||||
{
|
{
|
||||||
// Using CurrentCultureIgnoreCase since this is user facing
|
// Using CurrentCultureIgnoreCase since this is user facing
|
||||||
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
|
||||||
@@ -758,6 +760,7 @@ namespace PowerLauncher.ViewModel
|
|||||||
{
|
{
|
||||||
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