mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
enhance: avoid unhandled exceptions in timer
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
55be1ad1ca
commit
8e55ba1b47
1 changed files with 29 additions and 22 deletions
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue