@@ -489,19 +489,19 @@ public async Task ApplyFilesAndFoldersChangesAsync()
489
489
{
490
490
if ( filesAndFolders == null || filesAndFolders . Count == 0 )
491
491
{
492
- Action action = ( ) =>
492
+ void ClearDisplay ( )
493
493
{
494
494
FilesAndFolders . Clear ( ) ;
495
495
UpdateEmptyTextType ( ) ;
496
496
DirectoryInfoUpdated ? . Invoke ( this , EventArgs . Empty ) ;
497
- } ;
497
+ }
498
498
if ( CoreApplication . MainView . DispatcherQueue . HasThreadAccess )
499
499
{
500
- action ( ) ;
500
+ ClearDisplay ( ) ;
501
501
}
502
502
else
503
503
{
504
- await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( action ) ;
504
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ClearDisplay ) ;
505
505
}
506
506
return ;
507
507
}
@@ -517,7 +517,7 @@ public async Task ApplyFilesAndFoldersChangesAsync()
517
517
// After calling BeginBulkOperation, ObservableCollection.CollectionChanged is suppressed
518
518
// so modifies to FilesAndFolders won't trigger UI updates, hence below operations can be
519
519
// run safely without needs of dispatching to UI thread
520
- Action applyChangesAction = ( ) =>
520
+ void ApplyChanges ( )
521
521
{
522
522
var startIndex = - 1 ;
523
523
var tempList = new List < ListedItem > ( ) ;
@@ -572,26 +572,26 @@ void ApplyBulkInsertEntries()
572
572
{
573
573
OrderGroups ( ) ;
574
574
}
575
- } ;
575
+ }
576
576
577
- Action updateUIAction = ( ) =>
577
+ void UpdateUI ( )
578
578
{
579
579
// trigger CollectionChanged with NotifyCollectionChangedAction.Reset
580
580
// once loading is completed so that UI can be updated
581
581
FilesAndFolders . EndBulkOperation ( ) ;
582
582
UpdateEmptyTextType ( ) ;
583
583
DirectoryInfoUpdated ? . Invoke ( this , EventArgs . Empty ) ;
584
- } ;
584
+ }
585
585
586
586
if ( CoreApplication . MainView . DispatcherQueue . HasThreadAccess )
587
587
{
588
- await Task . Run ( applyChangesAction ) ;
589
- updateUIAction ( ) ;
588
+ await Task . Run ( ApplyChanges ) ;
589
+ UpdateUI ( ) ;
590
590
}
591
591
else
592
592
{
593
- applyChangesAction ( ) ;
594
- await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( updateUIAction ) ;
593
+ ApplyChanges ( ) ;
594
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( UpdateUI ) ;
595
595
}
596
596
}
597
597
catch ( Exception ex )
@@ -608,23 +608,23 @@ private Task OrderFilesAndFoldersAsync()
608
608
return Task . CompletedTask ;
609
609
}
610
610
611
- Action action = ( ) =>
611
+ void OrderEntries ( )
612
612
{
613
613
if ( filesAndFolders . Count == 0 )
614
614
{
615
615
return ;
616
616
}
617
617
618
618
filesAndFolders = SortingHelper . OrderFileList ( filesAndFolders , folderSettings . DirectorySortOption , folderSettings . DirectorySortDirection ) . ToList ( ) ;
619
- } ;
619
+ }
620
620
621
621
if ( CoreApplication . MainView . DispatcherQueue . HasThreadAccess )
622
622
{
623
- return Task . Run ( action ) ;
623
+ return Task . Run ( OrderEntries ) ;
624
624
}
625
625
else
626
626
{
627
- action ( ) ;
627
+ OrderEntries ( ) ;
628
628
return Task . CompletedTask ;
629
629
}
630
630
}
@@ -1584,16 +1584,20 @@ await DialogDisplayHelper.ShowDialogAsync(
1584
1584
}
1585
1585
else
1586
1586
{
1587
- List < ListedItem > fileList = await Win32StorageEnumerator . ListEntries ( path , returnformat , hFile , findData , Connection , cancellationToken , - 1 , intermediateAction : async ( intermediateList ) =>
1587
+ await Task . Run ( async ( ) =>
1588
1588
{
1589
- filesAndFolders . AddRange ( intermediateList ) ;
1589
+ List < ListedItem > fileList = await Win32StorageEnumerator . ListEntries ( path , returnformat , hFile , findData , Connection , cancellationToken , - 1 , intermediateAction : async ( intermediateList ) =>
1590
+ {
1591
+ filesAndFolders . AddRange ( intermediateList ) ;
1592
+ await OrderFilesAndFoldersAsync ( ) ;
1593
+ await ApplyFilesAndFoldersChangesAsync ( ) ;
1594
+ } ) ;
1595
+
1596
+ filesAndFolders . AddRange ( fileList ) ;
1590
1597
await OrderFilesAndFoldersAsync ( ) ;
1591
1598
await ApplyFilesAndFoldersChangesAsync ( ) ;
1592
1599
} ) ;
1593
1600
1594
- filesAndFolders . AddRange ( fileList ) ;
1595
- await OrderFilesAndFoldersAsync ( ) ;
1596
- await ApplyFilesAndFoldersChangesAsync ( ) ;
1597
1601
return 0 ;
1598
1602
}
1599
1603
}
@@ -1607,22 +1611,25 @@ private async Task EnumFromStorageFolderAsync(string path, ListedItem currentFol
1607
1611
ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
1608
1612
string returnformat = Enum . Parse < TimeStyle > ( localSettings . Values [ Constants . LocalSettings . DateTimeFormat ] . ToString ( ) ) == TimeStyle . Application ? "D" : "g" ;
1609
1613
1610
- List < ListedItem > finalList = await UniversalStorageEnumerator . ListEntries (
1611
- rootFolder ,
1612
- currentStorageFolder ,
1613
- returnformat ,
1614
- sourcePageType ,
1615
- cancellationToken ,
1616
- - 1 ,
1617
- async ( intermediateList ) =>
1614
+ await Task . Run ( async ( ) =>
1618
1615
{
1619
- filesAndFolders . AddRange ( intermediateList ) ;
1616
+ List < ListedItem > finalList = await UniversalStorageEnumerator . ListEntries (
1617
+ rootFolder ,
1618
+ currentStorageFolder ,
1619
+ returnformat ,
1620
+ sourcePageType ,
1621
+ cancellationToken ,
1622
+ - 1 ,
1623
+ async ( intermediateList ) =>
1624
+ {
1625
+ filesAndFolders . AddRange ( intermediateList ) ;
1626
+ await OrderFilesAndFoldersAsync ( ) ;
1627
+ await ApplyFilesAndFoldersChangesAsync ( ) ;
1628
+ } ) ;
1629
+ filesAndFolders . AddRange ( finalList ) ;
1620
1630
await OrderFilesAndFoldersAsync ( ) ;
1621
1631
await ApplyFilesAndFoldersChangesAsync ( ) ;
1622
1632
} ) ;
1623
- filesAndFolders . AddRange ( finalList ) ;
1624
- await OrderFilesAndFoldersAsync ( ) ;
1625
- await ApplyFilesAndFoldersChangesAsync ( ) ;
1626
1633
1627
1634
stopwatch . Stop ( ) ;
1628
1635
Debug . WriteLine ( $ "Enumerating items in { path } (device) completed in { stopwatch . ElapsedMilliseconds } milliseconds.\n ") ;
0 commit comments