From c6794dacadfd79241ebef0f685de8fa67d8425a4 Mon Sep 17 00:00:00 2001 From: Sina Hinderks Date: Sun, 7 Dec 2025 21:33:23 +0100 Subject: [PATCH] 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. --- src/ViewModels/Repository.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 036ed331e..c3ed2d40e 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1814,7 +1814,12 @@ private BranchTreeNode FindBranchNode(List nodes, string path) private void FetchInBackground(object sender) { - Dispatcher.UIThread.Invoke(async Task () => + Dispatcher.UIThread.Invoke(FetchInBackgroundOnUiThread); + } + + private async Task FetchInBackgroundOnUiThread() + { + try { if (_settings is not { EnableAutoFetch: true }) return; @@ -1856,7 +1861,11 @@ private void FetchInBackground(object sender) _lastFetchTime = DateTime.Now; IsAutoFetching = false; - }); + } + catch (OperationCanceledException) + { + // Ignore cancellation. + } } private readonly bool _isWorktree = false;