@@ -459,7 +459,7 @@ protected async void DrivesManager_PropertyChanged(object sender, PropertyChange
459459 await DisplayFilesystemConsentDialogAsync ( ) ;
460460 }
461461
462- private TaskCompletionSource ? _getDisplayNameTCS ;
462+ private volatile CancellationTokenSource ? cts ;
463463
464464 // Ensure that the path bar gets updated for user interaction
465465 // whenever the path changes.We will get the individual directories from
@@ -468,25 +468,25 @@ public async Task UpdatePathUIToWorkingDirectoryAsync(string newWorkingDir, stri
468468 {
469469 if ( string . IsNullOrWhiteSpace ( singleItemOverride ) )
470470 {
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 ( ) ;
475472
476473 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+
477483 ToolbarViewModel . PathComponents . Clear ( ) ;
478484 foreach ( var component in components )
479485 ToolbarViewModel . PathComponents . Add ( component ) ;
480-
481- tcs . TrySetResult ( ) ;
482- _getDisplayNameTCS = null ;
483486 }
484487 else
485488 {
486- // Wait if awaiting GetDirectoryPathComponentsWithDisplayNameAsync
487- var tcs = _getDisplayNameTCS ;
488- if ( tcs is not null )
489- await tcs . Task ;
489+ cts ? . Cancel ( ) ;
490490
491491 // Clear the path UI
492492 ToolbarViewModel . PathComponents . Clear ( ) ;
0 commit comments