33using System . Globalization ;
44using System . IO ;
55using System . Text . RegularExpressions ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78
89using Avalonia . Controls ;
@@ -171,7 +172,7 @@ public void Cleanup()
171172 _searchChangeFilter = null ;
172173 _diffContext = null ;
173174 _viewRevisionFileContent = null ;
174- _cancelToken = null ;
175+ _cancellationSource = null ;
175176 WebLinks . Clear ( ) ;
176177 _revisionFiles = null ;
177178 _revisionFileSearchSuggestion = null ;
@@ -589,41 +590,45 @@ private void Refresh()
589590 if ( _commit == null )
590591 return ;
591592
593+ if ( _cancellationSource is { IsCancellationRequested : false } )
594+ _cancellationSource . Cancel ( ) ;
595+
596+ _cancellationSource = new CancellationTokenSource ( ) ;
597+ var token = _cancellationSource . Token ;
598+
592599 Task . Run ( ( ) =>
593600 {
594601 var message = new Commands . QueryCommitFullMessage ( _repo . FullPath , _commit . SHA ) . Result ( ) ;
595602 var links = ParseLinksInMessage ( message ) ;
596- Dispatcher . UIThread . Invoke ( ( ) => FullMessage = new Models . CommitFullMessage { Message = message , Links = links } ) ;
603+
604+ if ( ! token . IsCancellationRequested )
605+ Dispatcher . UIThread . Invoke ( ( ) => FullMessage = new Models . CommitFullMessage { Message = message , Links = links } ) ;
597606 } ) ;
598607
599608 Task . Run ( ( ) =>
600609 {
601610 var signInfo = new Commands . QueryCommitSignInfo ( _repo . FullPath , _commit . SHA , ! _repo . HasAllowedSignersFile ) . Result ( ) ;
602- Dispatcher . UIThread . Invoke ( ( ) => SignInfo = signInfo ) ;
611+ if ( ! token . IsCancellationRequested )
612+ Dispatcher . UIThread . Invoke ( ( ) => SignInfo = signInfo ) ;
603613 } ) ;
604614
605- if ( _cancelToken != null )
606- _cancelToken . Requested = true ;
607-
608- _cancelToken = new Commands . Command . CancelToken ( ) ;
609-
610615 if ( Preferences . Instance . ShowChildren )
611616 {
612617 Task . Run ( ( ) =>
613618 {
614619 var max = Preferences . Instance . MaxHistoryCommits ;
615- var cmdChildren = new Commands . QueryCommitChildren ( _repo . FullPath , _commit . SHA , max ) { Cancel = _cancelToken } ;
616- var children = cmdChildren . Result ( ) ;
617- if ( ! cmdChildren . Cancel . Requested )
620+ var cmd = new Commands . QueryCommitChildren ( _repo . FullPath , _commit . SHA , max ) { CancellationToken = token } ;
621+ var children = cmd . Result ( ) ;
622+ if ( ! token . IsCancellationRequested )
618623 Dispatcher . UIThread . Post ( ( ) => Children = children ) ;
619624 } ) ;
620625 }
621626
622627 Task . Run ( ( ) =>
623628 {
624629 var parent = _commit . Parents . Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : _commit . Parents [ 0 ] ;
625- var cmdChanges = new Commands . CompareRevisions ( _repo . FullPath , parent , _commit . SHA ) { Cancel = _cancelToken } ;
626- var changes = cmdChanges . Result ( ) ;
630+ var cmd = new Commands . CompareRevisions ( _repo . FullPath , parent , _commit . SHA ) { CancellationToken = token } ;
631+ var changes = cmd . Result ( ) ;
627632 var visible = changes ;
628633 if ( ! string . IsNullOrWhiteSpace ( _searchChangeFilter ) )
629634 {
@@ -635,7 +640,7 @@ private void Refresh()
635640 }
636641 }
637642
638- if ( ! cmdChanges . Cancel . Requested )
643+ if ( ! token . IsCancellationRequested )
639644 {
640645 Dispatcher . UIThread . Post ( ( ) =>
641646 {
@@ -873,7 +878,7 @@ private void CalcRevisionFileSearchSuggestion()
873878 private string _searchChangeFilter = string . Empty ;
874879 private DiffContext _diffContext = null ;
875880 private object _viewRevisionFileContent = null ;
876- private Commands . Command . CancelToken _cancelToken = null ;
881+ private CancellationTokenSource _cancellationSource = null ;
877882 private List < string > _revisionFiles = null ;
878883 private string _revisionFileSearchFilter = string . Empty ;
879884 private List < string > _revisionFileSearchSuggestion = null ;
0 commit comments