File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . Threading ;
34using System . Threading . Tasks ;
45using Avalonia . Threading ;
56using CommunityToolkit . Mvvm . ComponentModel ;
@@ -105,6 +106,12 @@ public void StartSearch()
105106
106107 IsQuerying = true ;
107108
109+ if ( _cancellation is { IsCancellationRequested : false } )
110+ _cancellation . Cancel ( ) ;
111+
112+ _cancellation = new ( ) ;
113+ var token = _cancellation . Token ;
114+
108115 Task . Run ( async ( ) =>
109116 {
110117 var result = new List < Models . Commit > ( ) ;
@@ -158,17 +165,23 @@ public void StartSearch()
158165
159166 Dispatcher . UIThread . Post ( ( ) =>
160167 {
161- IsQuerying = false ;
168+ if ( token . IsCancellationRequested )
169+ return ;
162170
171+ IsQuerying = false ;
163172 if ( _repo . IsSearchingCommits )
164173 Results = result ;
165174 } ) ;
166- } ) ;
175+ } , token ) ;
167176 }
168177
169178 public void EndSearch ( )
170179 {
180+ if ( _cancellation is { IsCancellationRequested : false } )
181+ _cancellation . Cancel ( ) ;
182+
171183 _worktreeFiles = null ;
184+ IsQuerying = false ;
172185 Suggestions = null ;
173186 Results = null ;
174187 GC . Collect ( ) ;
@@ -228,6 +241,7 @@ private void UpdateSuggestions()
228241 }
229242
230243 private Repository _repo = null ;
244+ private CancellationTokenSource _cancellation = null ;
231245 private int _method = ( int ) Models . CommitSearchMethod . ByMessage ;
232246 private string _filter = string . Empty ;
233247 private bool _onlySearchCurrentBranch = false ;
You can’t perform that action at this time.
0 commit comments