enhance: threadsafe way to accessing _remotes (#882)

This commit is contained in:
leo 2025-01-08 19:20:27 +08:00
parent 94c532889b
commit 0e34a77add
No known key found for this signature in database

View file

@ -881,7 +881,9 @@ namespace SourceGit.ViewModels
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
Remotes = remotes; lock (_lockRemotes)
Remotes = remotes;
Branches = branches; Branches = branches;
CurrentBranch = branches.Find(x => x.IsCurrent); CurrentBranch = branches.Find(x => x.IsCurrent);
LocalBranchTrees = builder.Locals; LocalBranchTrees = builder.Locals;
@ -2299,8 +2301,11 @@ namespace SourceGit.ViewModels
return; return;
var remotes = new List<string>(); var remotes = new List<string>();
foreach (var remote in _remotes) lock (_lockRemotes)
remotes.Add(remote.Name); {
foreach (var remote in _remotes)
remotes.Add(remote.Name);
}
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
foreach (var remote in remotes) foreach (var remote in remotes)
@ -2336,6 +2341,7 @@ namespace SourceGit.ViewModels
private List<string> _revisionFiles = new List<string>(); private List<string> _revisionFiles = new List<string>();
private string _filter = string.Empty; private string _filter = string.Empty;
private object _lockRemotes = new object();
private List<Models.Remote> _remotes = new List<Models.Remote>(); private List<Models.Remote> _remotes = new List<Models.Remote>();
private List<Models.Branch> _branches = new List<Models.Branch>(); private List<Models.Branch> _branches = new List<Models.Branch>();
private Models.Branch _currentBranch = null; private Models.Branch _currentBranch = null;