From 0e34a77add6ac712928d0e42555546b416e300c1 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 8 Jan 2025 19:20:27 +0800 Subject: [PATCH] enhance: threadsafe way to accessing `_remotes` (#882) --- src/ViewModels/Repository.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index a323cc92..056736c0 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -881,7 +881,9 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => { - Remotes = remotes; + lock (_lockRemotes) + Remotes = remotes; + Branches = branches; CurrentBranch = branches.Find(x => x.IsCurrent); LocalBranchTrees = builder.Locals; @@ -2299,8 +2301,11 @@ namespace SourceGit.ViewModels return; var remotes = new List(); - 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) @@ -2336,6 +2341,7 @@ namespace SourceGit.ViewModels private List _revisionFiles = new List(); private string _filter = string.Empty; + private object _lockRemotes = new object(); private List _remotes = new List(); private List _branches = new List(); private Models.Branch _currentBranch = null;