@@ -692,67 +692,21 @@ void ClearDisplay()
692
692
var isSemaphoreReleased = false ;
693
693
try
694
694
{
695
- FilesAndFolders . BeginBulkOperation ( ) ;
696
-
697
- // After calling BeginBulkOperation, ObservableCollection.CollectionChanged is suppressed
698
- // so modifies to FilesAndFolders won't trigger UI updates, hence below operations can be
699
- // run safely without needs of dispatching to UI thread
700
- void ApplyChanges ( )
695
+ await dispatcherQueue . EnqueueOrInvokeAsync ( ( ) =>
701
696
{
702
- var startIndex = - 1 ;
703
- var tempList = new List < ListedItem > ( ) ;
704
-
705
- void ApplyBulkInsertEntries ( )
697
+ try
706
698
{
707
- if ( startIndex != - 1 )
708
- {
709
- FilesAndFolders . ReplaceRange ( startIndex , tempList ) ;
710
- startIndex = - 1 ;
711
- tempList . Clear ( ) ;
712
- }
713
- }
699
+ FilesAndFolders . BeginBulkOperation ( ) ;
714
700
715
- for ( var i = 0 ; i < filesAndFoldersLocal . Count ; i ++ )
716
- {
717
701
if ( addFilesCTS . IsCancellationRequested )
718
702
return ;
719
703
720
- if ( i < FilesAndFolders . Count )
721
- {
722
- if ( FilesAndFolders [ i ] != filesAndFoldersLocal [ i ] )
723
- {
724
- if ( startIndex == - 1 )
725
- startIndex = i ;
704
+ FilesAndFolders . Clear ( ) ;
705
+ FilesAndFolders . AddRange ( filesAndFoldersLocal ) ;
726
706
727
- tempList . Add ( filesAndFoldersLocal [ i ] ) ;
728
- }
729
- else
730
- {
731
- ApplyBulkInsertEntries ( ) ;
732
- }
733
- }
734
- else
735
- {
736
- ApplyBulkInsertEntries ( ) ;
737
- FilesAndFolders . InsertRange ( i , filesAndFoldersLocal . Skip ( i ) ) ;
707
+ if ( folderSettings . DirectoryGroupOption != GroupOption . None )
708
+ OrderGroups ( ) ;
738
709
739
- break ;
740
- }
741
- }
742
-
743
- ApplyBulkInsertEntries ( ) ;
744
-
745
- if ( FilesAndFolders . Count > filesAndFoldersLocal . Count )
746
- FilesAndFolders . RemoveRange ( filesAndFoldersLocal . Count , FilesAndFolders . Count - filesAndFoldersLocal . Count ) ;
747
-
748
- if ( folderSettings . DirectoryGroupOption != GroupOption . None )
749
- OrderGroups ( ) ;
750
- }
751
-
752
- void UpdateUI ( )
753
- {
754
- try
755
- {
756
710
// Trigger CollectionChanged with NotifyCollectionChangedAction.Reset
757
711
// once loading is completed so that UI can be updated
758
712
FilesAndFolders . EndBulkOperation ( ) ;
@@ -764,21 +718,10 @@ void UpdateUI()
764
718
isSemaphoreReleased = true ;
765
719
bulkOperationSemaphore . Release ( ) ;
766
720
}
767
- }
768
-
769
- if ( NativeWinApiHelper . IsHasThreadAccessPropertyPresent && dispatcherQueue . HasThreadAccess )
770
- {
771
- await Task . Run ( ApplyChanges ) ;
772
- UpdateUI ( ) ;
773
- }
774
- else
775
- {
776
- ApplyChanges ( ) ;
777
- await dispatcherQueue . EnqueueOrInvokeAsync ( UpdateUI ) ;
721
+ } ) ;
778
722
779
- // The semaphore will be released in UI thread
780
- isSemaphoreReleased = true ;
781
- }
723
+ // The semaphore will be released in UI thread
724
+ isSemaphoreReleased = true ;
782
725
}
783
726
finally
784
727
{
@@ -806,10 +749,6 @@ private Task RequestSelectionAsync(List<ListedItem> itemsToSelect)
806
749
807
750
private Task OrderFilesAndFoldersAsync ( )
808
751
{
809
- // Sorting group contents is handled elsewhere
810
- if ( folderSettings . DirectoryGroupOption != GroupOption . None )
811
- return Task . CompletedTask ;
812
-
813
752
void OrderEntries ( )
814
753
{
815
754
if ( filesAndFolders . Count == 0 )
@@ -886,32 +825,25 @@ public async Task GroupOptionsUpdatedAsync(CancellationToken token)
886
825
var isSemaphoreReleased = false ;
887
826
try
888
827
{
889
- FilesAndFolders . BeginBulkOperation ( ) ;
890
- UpdateGroupOptions ( ) ;
891
-
892
- if ( FilesAndFolders . IsGrouped )
828
+ await dispatcherQueue . EnqueueOrInvokeAsync ( ( ) =>
893
829
{
894
- await Task . Run ( ( ) =>
830
+ try
895
831
{
896
- FilesAndFolders . ResetGroups ( token ) ;
897
- if ( token . IsCancellationRequested )
898
- return ;
832
+ FilesAndFolders . BeginBulkOperation ( ) ;
833
+ UpdateGroupOptions ( ) ;
899
834
900
- OrderGroups ( ) ;
901
- } ) ;
902
- }
903
- else
904
- {
905
- await OrderFilesAndFoldersAsync ( ) ;
906
- }
835
+ if ( FilesAndFolders . IsGrouped )
836
+ {
837
+ FilesAndFolders . ResetGroups ( token ) ;
838
+ if ( token . IsCancellationRequested )
839
+ return ;
907
840
908
- if ( token . IsCancellationRequested )
909
- return ;
841
+ OrderGroups ( ) ;
842
+ }
843
+
844
+ if ( token . IsCancellationRequested )
845
+ return ;
910
846
911
- await dispatcherQueue . EnqueueOrInvokeAsync ( ( ) =>
912
- {
913
- try
914
- {
915
847
FilesAndFolders . EndBulkOperation ( ) ;
916
848
}
917
849
finally
@@ -1043,7 +975,7 @@ await dispatcherQueue.EnqueueOrInvokeAsync(async () =>
1043
975
// Add the file icon to the DefaultIcons list
1044
976
if
1045
977
(
1046
- ! DefaultIcons . ContainsKey ( item . FileExtension . ToLowerInvariant ( ) ) &&
978
+ ! DefaultIcons . ContainsKey ( item . FileExtension . ToLowerInvariant ( ) ) &&
1047
979
! string . IsNullOrEmpty ( item . FileExtension ) &&
1048
980
! item . IsShortcut &&
1049
981
! item . IsExecutable
0 commit comments