Skip to content

Commit

Permalink
enhance: threadsafe way to accessing _remotes (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
love-linger committed Jan 8, 2025
1 parent 94c5328 commit 0e34a77
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ public void RefreshBranches()

Dispatcher.UIThread.Invoke(() =>
{
Remotes = remotes;
lock (_lockRemotes)
Remotes = remotes;

Branches = branches;
CurrentBranch = branches.Find(x => x.IsCurrent);
LocalBranchTrees = builder.Locals;
Expand Down Expand Up @@ -2299,8 +2301,11 @@ private void AutoFetchImpl(object sender)
return;

var remotes = new List<string>();
foreach (var remote in _remotes)
remotes.Add(remote.Name);
lock (_lockRemotes)
{
foreach (var remote in _remotes)
remotes.Add(remote.Name);
}

Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
foreach (var remote in remotes)
Expand Down Expand Up @@ -2336,6 +2341,7 @@ private void AutoFetchImpl(object sender)
private List<string> _revisionFiles = new List<string>();

private string _filter = string.Empty;
private object _lockRemotes = new object();
private List<Models.Remote> _remotes = new List<Models.Remote>();
private List<Models.Branch> _branches = new List<Models.Branch>();
private Models.Branch _currentBranch = null;
Expand Down

0 comments on commit 0e34a77

Please sign in to comment.