@@ -560,7 +560,8 @@ public void Open()
560560 _selectedViewIndex = 0 ;
561561
562562 _workingCopy . CommitMessage = _settings . LastCommitMessage ;
563- _autoFetchTimer = new Timer ( AutoFetchImpl , null , 5000 , 5000 ) ;
563+ _lastFetchTime = DateTime . Now ;
564+ _autoFetchTimer = new Timer ( AutoFetchInBackground , null , 5000 , 5000 ) ;
564565 RefreshAll ( ) ;
565566 }
566567
@@ -1194,9 +1195,7 @@ public void RefreshBranches()
11941195
11951196 Dispatcher . UIThread . Invoke ( ( ) =>
11961197 {
1197- lock ( _lockRemotes )
1198- Remotes = remotes ;
1199-
1198+ Remotes = remotes ;
12001199 Branches = branches ;
12011200 CurrentBranch = branches . Find ( x => x . IsCurrent ) ;
12021201 LocalBranchTrees = builder . Locals ;
@@ -1960,13 +1959,19 @@ private void CalcMatchedFilesForSearching()
19601959 MatchedFilesForSearching = matched ;
19611960 }
19621961
1963- private async void AutoFetchImpl ( object sender )
1962+ private void AutoFetchInBackground ( object sender )
19641963 {
1965- try
1964+ Dispatcher . UIThread . Post ( async ( ) =>
19661965 {
1967- if ( ! _settings . EnableAutoFetch || _isAutoFetching )
1966+ if ( _settings == null || ! _settings . EnableAutoFetch )
19681967 return ;
19691968
1969+ if ( ! CanCreatePopup ( ) )
1970+ {
1971+ _lastFetchTime = DateTime . Now ;
1972+ return ;
1973+ }
1974+
19701975 var lockFile = Path . Combine ( _gitDir , "index.lock" ) ;
19711976 if ( File . Exists ( lockFile ) )
19721977 return ;
@@ -1976,36 +1981,25 @@ private async void AutoFetchImpl(object sender)
19761981 if ( desire > now )
19771982 return ;
19781983
1979- var remotes = new List < string > ( ) ;
1980- lock ( _lockRemotes )
1981- {
1982- foreach ( var remote in _remotes )
1983- remotes . Add ( remote . Name ) ;
1984- }
1985-
1986- Dispatcher . UIThread . Invoke ( ( ) => IsAutoFetching = true ) ;
1984+ IsAutoFetching = true ;
19871985
19881986 if ( _settings . FetchAllRemotes )
19891987 {
1990- foreach ( var remote in remotes )
1991- await new Commands . Fetch ( _fullpath , remote , false , false ) { RaiseError = false } . RunAsync ( ) ;
1988+ foreach ( var remote in _remotes )
1989+ await new Commands . Fetch ( _fullpath , remote . Name , false , false ) { RaiseError = false } . RunAsync ( ) ;
19921990 }
1993- else if ( remotes . Count > 0 )
1991+ else if ( _remotes . Count > 0 )
19941992 {
19951993 var remote = string . IsNullOrEmpty ( _settings . DefaultRemote ) ?
1996- remotes . Find ( x => x . Equals ( _settings . DefaultRemote , StringComparison . Ordinal ) ) :
1997- remotes [ 0 ] ;
1994+ _remotes . Find ( x => x . Name . Equals ( _settings . DefaultRemote , StringComparison . Ordinal ) ) :
1995+ _remotes [ 0 ] ;
19981996
1999- await new Commands . Fetch ( _fullpath , remote , false , false ) { RaiseError = false } . RunAsync ( ) ;
1997+ await new Commands . Fetch ( _fullpath , remote . Name , false , false ) { RaiseError = false } . RunAsync ( ) ;
20001998 }
20011999
20022000 _lastFetchTime = DateTime . Now ;
2003- Dispatcher . UIThread . Invoke ( ( ) => IsAutoFetching = false ) ;
2004- }
2005- catch
2006- {
2007- // DO nothing, but prevent `System.AggregateException`
2008- }
2001+ IsAutoFetching = false ;
2002+ } ) ;
20092003 }
20102004
20112005 private string _fullpath = string . Empty ;
@@ -2037,7 +2031,6 @@ private async void AutoFetchImpl(object sender)
20372031 private List < string > _matchedFilesForSearching = null ;
20382032
20392033 private string _filter = string . Empty ;
2040- private readonly Lock _lockRemotes = new ( ) ;
20412034 private List < Models . Remote > _remotes = new List < Models . Remote > ( ) ;
20422035 private List < Models . Branch > _branches = new List < Models . Branch > ( ) ;
20432036 private Models . Branch _currentBranch = null ;
0 commit comments