Skip to content

Commit

Permalink
Lock both lists at the same time (#422)
Browse files Browse the repository at this point in the history
In #416 I tried to lock the lists before we modify them. 

Problem was, on L143 I only locked the `FilteredItems`, when `Items` can change there too. 

One singular lock for both makes the most sense anyways.
  • Loading branch information
zadjii-msft authored Feb 13, 2025
1 parent 38a7f18 commit 36f42d9
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public partial class ListViewModel : PageViewModel

private readonly ExtensionObject<IListPage> _model;

private readonly Lock _listLock = new();

public event TypedEventHandler<ListViewModel, object>? ItemsUpdated;

// Remember - "observable" properties from the model (via PropChanged)
Expand Down Expand Up @@ -82,7 +84,7 @@ protected override void OnFilterUpdated(string filter)
else
{
// But for all normal pages, we should run our fuzzy match on them.
lock (FilteredItems)
lock (_listLock)
{
ApplyFilterUnderLock();
}
Expand Down Expand Up @@ -117,7 +119,7 @@ private void FetchItems()
}
}

lock (Items)
lock (_listLock)
{
// Now that we have new ViewModels for everything from the
// extension, smartly update our list of VMs
Expand All @@ -138,7 +140,7 @@ private void FetchItems()
Task.Factory.StartNew(
() =>
{
lock (FilteredItems)
lock (_listLock)
{
// Now that our Items contains everything we want, it's time for us to
// re-evaluate our Filter on those items.
Expand Down

0 comments on commit 36f42d9

Please sign in to comment.