Skip to content

Commit c6794da

Browse files
committed
fix: prevent cancel exception when quitting SourceGit
Quitting SourceGit while a background fetch was active resulted in an exception. This exception was infrequently, and I only remember seeing it while debugging the SourceGit code.
1 parent 0cf7549 commit c6794da

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ViewModels/Repository.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,12 @@ private BranchTreeNode FindBranchNode(List<BranchTreeNode> nodes, string path)
18141814

18151815
private void FetchInBackground(object sender)
18161816
{
1817-
Dispatcher.UIThread.Invoke(async Task () =>
1817+
Dispatcher.UIThread.Invoke(FetchInBackgroundOnUiThread);
1818+
}
1819+
1820+
private async Task FetchInBackgroundOnUiThread()
1821+
{
1822+
try
18181823
{
18191824
if (_settings is not { EnableAutoFetch: true })
18201825
return;
@@ -1856,7 +1861,11 @@ private void FetchInBackground(object sender)
18561861

18571862
_lastFetchTime = DateTime.Now;
18581863
IsAutoFetching = false;
1859-
});
1864+
}
1865+
catch (OperationCanceledException)
1866+
{
1867+
// Ignore cancellation.
1868+
}
18601869
}
18611870

18621871
private readonly bool _isWorktree = false;

0 commit comments

Comments
 (0)