enhance: avoid unhandled exceptions in timer

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-31 19:06:10 +08:00
parent 55be1ad1ca
commit 8e55ba1b47
No known key found for this signature in database

View file

@ -2513,30 +2513,37 @@ namespace SourceGit.ViewModels
private void AutoFetchImpl(object sender) private void AutoFetchImpl(object sender)
{ {
if (!_settings.EnableAutoFetch || _isAutoFetching) try
return;
var lockFile = Path.Combine(_gitDir, "index.lock");
if (File.Exists(lockFile))
return;
var now = DateTime.Now;
var desire = _lastFetchTime.AddMinutes(_settings.AutoFetchInterval);
if (desire > now)
return;
var remotes = new List<string>();
lock (_lockRemotes)
{ {
foreach (var remote in _remotes) if (!_settings.EnableAutoFetch || _isAutoFetching)
remotes.Add(remote.Name); return;
}
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); var lockFile = Path.Combine(_gitDir, "index.lock");
foreach (var remote in remotes) if (File.Exists(lockFile))
new Commands.Fetch(_fullpath, remote, false, false, null) { RaiseError = false }.Exec(); return;
_lastFetchTime = DateTime.Now;
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); var now = DateTime.Now;
var desire = _lastFetchTime.AddMinutes(_settings.AutoFetchInterval);
if (desire > now)
return;
var remotes = new List<string>();
lock (_lockRemotes)
{
foreach (var remote in _remotes)
remotes.Add(remote.Name);
}
Dispatcher.UIThread.Invoke(() => IsAutoFetching = true);
foreach (var remote in remotes)
new Commands.Fetch(_fullpath, remote, false, false, null) { RaiseError = false }.Exec();
_lastFetchTime = DateTime.Now;
Dispatcher.UIThread.Invoke(() => IsAutoFetching = false);
}
catch
{
// DO nothing, but prevent `System.AggregateException`
}
} }
private string _fullpath = string.Empty; private string _fullpath = string.Empty;