@@ -578,6 +578,17 @@ public void Close()
578
578
JsonSerializer . Serialize ( stream , _settings , JsonCodeGen . Default . RepositorySettings ) ;
579
579
}
580
580
581
+ if ( _cancellationRefreshBranches is { IsCancellationRequested : false } )
582
+ _cancellationRefreshBranches . Cancel ( ) ;
583
+ if ( _cancellationRefreshTags is { IsCancellationRequested : false } )
584
+ _cancellationRefreshTags . Cancel ( ) ;
585
+ if ( _cancellationRefreshWorkingCopyChanges is { IsCancellationRequested : false } )
586
+ _cancellationRefreshWorkingCopyChanges . Cancel ( ) ;
587
+ if ( _cancellationRefreshCommits is { IsCancellationRequested : false } )
588
+ _cancellationRefreshCommits . Cancel ( ) ;
589
+ if ( _cancellationRefreshStashes is { IsCancellationRequested : false } )
590
+ _cancellationRefreshStashes . Cancel ( ) ;
591
+
581
592
_autoFetchTimer . Dispose ( ) ;
582
593
_autoFetchTimer = null ;
583
594
@@ -1170,6 +1181,12 @@ public bool MayHaveSubmodules()
1170
1181
1171
1182
public void RefreshBranches ( )
1172
1183
{
1184
+ if ( _cancellationRefreshBranches is { IsCancellationRequested : false } )
1185
+ _cancellationRefreshBranches . Cancel ( ) ;
1186
+
1187
+ _cancellationRefreshBranches = new CancellationTokenSource ( ) ;
1188
+ var token = _cancellationRefreshBranches . Token ;
1189
+
1173
1190
Task . Run ( async ( ) =>
1174
1191
{
1175
1192
var branches = await new Commands . QueryBranches ( FullPath ) . GetResultAsync ( ) . ConfigureAwait ( false ) ;
@@ -1178,6 +1195,9 @@ public void RefreshBranches()
1178
1195
1179
1196
Dispatcher . UIThread . Invoke ( ( ) =>
1180
1197
{
1198
+ if ( token . IsCancellationRequested )
1199
+ return ;
1200
+
1181
1201
Remotes = remotes ;
1182
1202
Branches = branches ;
1183
1203
CurrentBranch = branches . Find ( x => x . IsCurrent ) ;
@@ -1198,7 +1218,7 @@ public void RefreshBranches()
1198
1218
var hasPendingPullOrPush = CurrentBranch ? . TrackStatus . IsVisible ?? false ;
1199
1219
GetOwnerPage ( ) ? . ChangeDirtyState ( Models . DirtyState . HasPendingPullOrPush , ! hasPendingPullOrPush ) ;
1200
1220
} ) ;
1201
- } ) ;
1221
+ } , token ) ;
1202
1222
}
1203
1223
1204
1224
public void RefreshWorktrees ( )
@@ -1228,19 +1248,34 @@ public void RefreshWorktrees()
1228
1248
1229
1249
public void RefreshTags ( )
1230
1250
{
1251
+ if ( _cancellationRefreshTags is { IsCancellationRequested : false } )
1252
+ _cancellationRefreshTags . Cancel ( ) ;
1253
+
1254
+ _cancellationRefreshTags = new CancellationTokenSource ( ) ;
1255
+ var token = _cancellationRefreshTags . Token ;
1256
+
1231
1257
Task . Run ( async ( ) =>
1232
1258
{
1233
1259
var tags = await new Commands . QueryTags ( FullPath ) . GetResultAsync ( ) . ConfigureAwait ( false ) ;
1234
1260
Dispatcher . UIThread . Invoke ( ( ) =>
1235
1261
{
1262
+ if ( token . IsCancellationRequested )
1263
+ return ;
1264
+
1236
1265
Tags = tags ;
1237
1266
VisibleTags = BuildVisibleTags ( ) ;
1238
1267
} ) ;
1239
- } ) ;
1268
+ } , token ) ;
1240
1269
}
1241
1270
1242
1271
public void RefreshCommits ( )
1243
1272
{
1273
+ if ( _cancellationRefreshCommits is { IsCancellationRequested : false } )
1274
+ _cancellationRefreshCommits . Cancel ( ) ;
1275
+
1276
+ _cancellationRefreshCommits = new CancellationTokenSource ( ) ;
1277
+ var token = _cancellationRefreshCommits . Token ;
1278
+
1244
1279
Task . Run ( async ( ) =>
1245
1280
{
1246
1281
await Dispatcher . UIThread . InvokeAsync ( ( ) => _histories . IsLoading = true ) ;
@@ -1273,6 +1308,9 @@ public void RefreshCommits()
1273
1308
1274
1309
Dispatcher . UIThread . Invoke ( ( ) =>
1275
1310
{
1311
+ if ( token . IsCancellationRequested )
1312
+ return ;
1313
+
1276
1314
if ( _histories != null )
1277
1315
{
1278
1316
_histories . IsLoading = false ;
@@ -1287,7 +1325,7 @@ public void RefreshCommits()
1287
1325
1288
1326
_navigateToCommitDelayed = string . Empty ;
1289
1327
} ) ;
1290
- } ) ;
1328
+ } , token ) ;
1291
1329
}
1292
1330
1293
1331
public void RefreshSubmodules ( )
@@ -1352,43 +1390,61 @@ public void RefreshWorkingCopyChanges()
1352
1390
if ( IsBare )
1353
1391
return ;
1354
1392
1393
+ if ( _cancellationRefreshWorkingCopyChanges is { IsCancellationRequested : false } )
1394
+ _cancellationRefreshWorkingCopyChanges . Cancel ( ) ;
1395
+
1396
+ _cancellationRefreshWorkingCopyChanges = new CancellationTokenSource ( ) ;
1397
+ var token = _cancellationRefreshWorkingCopyChanges . Token ;
1398
+
1355
1399
Task . Run ( async ( ) =>
1356
1400
{
1357
1401
var changes = await new Commands . QueryLocalChanges ( FullPath , _settings . IncludeUntrackedInLocalChanges )
1358
1402
. GetResultAsync ( )
1359
1403
. ConfigureAwait ( false ) ;
1360
1404
1361
- if ( _workingCopy == null )
1405
+ if ( _workingCopy == null || token . IsCancellationRequested )
1362
1406
return ;
1363
1407
1364
1408
changes . Sort ( ( l , r ) => Models . NumericSort . Compare ( l . Path , r . Path ) ) ;
1365
- _workingCopy . SetData ( changes ) ;
1409
+ _workingCopy . SetData ( changes , token ) ;
1366
1410
1367
1411
Dispatcher . UIThread . Invoke ( ( ) =>
1368
1412
{
1413
+ if ( token . IsCancellationRequested )
1414
+ return ;
1415
+
1369
1416
LocalChangesCount = changes . Count ;
1370
1417
OnPropertyChanged ( nameof ( InProgressContext ) ) ;
1371
1418
GetOwnerPage ( ) ? . ChangeDirtyState ( Models . DirtyState . HasLocalChanges , changes . Count == 0 ) ;
1372
1419
} ) ;
1373
- } ) ;
1420
+ } , token ) ;
1374
1421
}
1375
1422
1376
1423
public void RefreshStashes ( )
1377
1424
{
1378
1425
if ( IsBare )
1379
1426
return ;
1380
1427
1428
+ if ( _cancellationRefreshStashes is { IsCancellationRequested : false } )
1429
+ _cancellationRefreshStashes . Cancel ( ) ;
1430
+
1431
+ _cancellationRefreshStashes = new CancellationTokenSource ( ) ;
1432
+ var token = _cancellationRefreshStashes . Token ;
1433
+
1381
1434
Task . Run ( async ( ) =>
1382
1435
{
1383
1436
var stashes = await new Commands . QueryStashes ( FullPath ) . GetResultAsync ( ) . ConfigureAwait ( false ) ;
1384
1437
Dispatcher . UIThread . Invoke ( ( ) =>
1385
1438
{
1439
+ if ( token . IsCancellationRequested )
1440
+ return ;
1441
+
1386
1442
if ( _stashesPage != null )
1387
1443
_stashesPage . Stashes = stashes ;
1388
1444
1389
1445
StashesCount = stashes . Count ;
1390
1446
} ) ;
1391
- } ) ;
1447
+ } , token ) ;
1392
1448
}
1393
1449
1394
1450
public void ToggleHistoryShowFlag ( Models . HistoryShowFlags flag )
@@ -2021,6 +2077,7 @@ private void FetchInBackground(object sender)
2021
2077
private object _visibleTags = null ;
2022
2078
private List < Models . Submodule > _submodules = [ ] ;
2023
2079
private object _visibleSubmodules = null ;
2080
+ private string _navigateToCommitDelayed = string . Empty ;
2024
2081
2025
2082
private bool _isAutoFetching = false ;
2026
2083
private Timer _autoFetchTimer = null ;
@@ -2029,6 +2086,10 @@ private void FetchInBackground(object sender)
2029
2086
private Models . BisectState _bisectState = Models . BisectState . None ;
2030
2087
private bool _isBisectCommandRunning = false ;
2031
2088
2032
- private string _navigateToCommitDelayed = string . Empty ;
2089
+ private CancellationTokenSource _cancellationRefreshBranches = null ;
2090
+ private CancellationTokenSource _cancellationRefreshTags = null ;
2091
+ private CancellationTokenSource _cancellationRefreshWorkingCopyChanges = null ;
2092
+ private CancellationTokenSource _cancellationRefreshCommits = null ;
2093
+ private CancellationTokenSource _cancellationRefreshStashes = null ;
2033
2094
}
2034
2095
}
0 commit comments