@@ -459,7 +459,7 @@ protected async void DrivesManager_PropertyChanged(object sender, PropertyChange
459
459
await DisplayFilesystemConsentDialogAsync ( ) ;
460
460
}
461
461
462
- private TaskCompletionSource ? _getDisplayNameTCS ;
462
+ private volatile CancellationTokenSource ? cts ;
463
463
464
464
// Ensure that the path bar gets updated for user interaction
465
465
// whenever the path changes.We will get the individual directories from
@@ -468,25 +468,25 @@ public async Task UpdatePathUIToWorkingDirectoryAsync(string newWorkingDir, stri
468
468
{
469
469
if ( string . IsNullOrWhiteSpace ( singleItemOverride ) )
470
470
{
471
- // We need override the path bar when searching, so we use TaskCompletionSource
472
- // to ensure that the override occurs after GetDirectoryPathComponentsWithDisplayNameAsync.
473
- var tcs = new TaskCompletionSource ( ) ;
474
- _getDisplayNameTCS = tcs ;
471
+ cts = new CancellationTokenSource ( ) ;
475
472
476
473
var components = await StorageFileExtensions . GetDirectoryPathComponentsWithDisplayNameAsync ( newWorkingDir ) ;
474
+
475
+ // Cancel if overrided by single item
476
+ if ( cts . IsCancellationRequested )
477
+ {
478
+ cts = null ;
479
+ return ;
480
+ }
481
+ cts = null ;
482
+
477
483
ToolbarViewModel . PathComponents . Clear ( ) ;
478
484
foreach ( var component in components )
479
485
ToolbarViewModel . PathComponents . Add ( component ) ;
480
-
481
- tcs . TrySetResult ( ) ;
482
- _getDisplayNameTCS = null ;
483
486
}
484
487
else
485
488
{
486
- // Wait if awaiting GetDirectoryPathComponentsWithDisplayNameAsync
487
- var tcs = _getDisplayNameTCS ;
488
- if ( tcs is not null )
489
- await tcs . Task ;
489
+ cts ? . Cancel ( ) ;
490
490
491
491
// Clear the path UI
492
492
ToolbarViewModel . PathComponents . Clear ( ) ;
0 commit comments