From ceb56d5d178b87a92fa3bb2a5469b9a6e85ec641 Mon Sep 17 00:00:00 2001 From: Sina Hinderks Date: Mon, 8 Dec 2025 03:32:51 +0100 Subject: [PATCH] fix: prevent cancel exception when quitting SourceGit (#1962) 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 036ed331..c3ed2d40 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1814,7 +1814,12 @@ namespace SourceGit.ViewModels 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 @@ namespace SourceGit.ViewModels _lastFetchTime = DateTime.Now; IsAutoFetching = false; - }); + } + catch (OperationCanceledException) + { + // Ignore cancellation. + } } private readonly bool _isWorktree = false;