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.
This commit is contained in:
Sina Hinderks
2025-12-08 03:32:51 +01:00
committed by GitHub
parent 286b8d4a95
commit ceb56d5d17

View File

@@ -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;