10
10
using System . Threading ;
11
11
using System . Threading . Tasks ;
12
12
using Windows . ApplicationModel . Core ;
13
- using Windows . UI . Core ;
14
13
using static Files . Helpers . NativeFindStorageItemHelper ;
15
14
16
15
namespace Files . Filesystem
@@ -34,8 +33,6 @@ internal class FolderSizeProvider : IFolderSizeProvider, IDisposable
34
33
{
35
34
private readonly IPreferencesSettingsService preferencesSettingsService = Ioc . Default . GetService < IPreferencesSettingsService > ( ) ;
36
35
37
- private readonly CoreDispatcher dispatcher = CoreApplication . MainView . CoreWindow . Dispatcher ;
38
-
39
36
private readonly IDictionary < string , long > cacheSizes = new Dictionary < string , long > ( ) ;
40
37
41
38
public event EventHandler < FolderSizeChangedEventArgs > FolderSizeChanged ;
@@ -57,14 +54,14 @@ public async void CleanCache()
57
54
58
55
var drives = DriveInfo . GetDrives ( ) . Select ( drive => drive . Name ) . ToArray ( ) ;
59
56
60
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
57
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) =>
61
58
{
62
59
var oldPaths = cacheSizes . Keys . Where ( path => ! drives . Any ( drive => path . StartsWith ( drive ) ) ) . ToList ( ) ;
63
60
foreach ( var oldPath in oldPaths )
64
61
{
65
62
cacheSizes . Remove ( oldPath ) ;
66
63
}
67
- } ) ;
64
+ } , Windows . System . DispatcherQueuePriority . Low ) ;
68
65
}
69
66
70
67
public async void UpdateFolder ( ListedItem folder , CancellationToken cancellationToken )
@@ -76,7 +73,7 @@ public async void UpdateFolder(ListedItem folder, CancellationToken cancellation
76
73
77
74
if ( folder . PrimaryItemAttribute == Windows . Storage . StorageItemTypes . Folder && folder . ContainsFilesOrFolders )
78
75
{
79
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
76
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) =>
80
77
{
81
78
if ( cacheSizes . ContainsKey ( folder . ItemPath ) )
82
79
{
@@ -90,17 +87,17 @@ await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
90
87
folder . FileSize = "ItemSizeNotCalculated" . GetLocalized ( ) ;
91
88
RaiseSizeChanged ( folder ) ;
92
89
}
93
- } ) ;
90
+ } , Windows . System . DispatcherQueuePriority . Low ) ;
94
91
95
92
long size = await Calculate ( folder . ItemPath ) ;
96
93
97
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
94
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) =>
98
95
{
99
96
cacheSizes [ folder . ItemPath ] = size ;
100
97
folder . FileSizeBytes = size ;
101
98
folder . FileSize = size . ToSizeString ( ) ;
102
99
RaiseSizeChanged ( folder ) ;
103
- } ) ;
100
+ } , Windows . System . DispatcherQueuePriority . Low ) ;
104
101
}
105
102
106
103
async Task < long > Calculate ( string folderPath , int level = 0 )
@@ -135,7 +132,7 @@ async Task<long> Calculate(string folderPath, int level = 0)
135
132
136
133
if ( level <= 3 )
137
134
{
138
- await dispatcher . RunAsync ( CoreDispatcherPriority . Low , ( ) =>
135
+ await CoreApplication . MainView . DispatcherQueue . EnqueueAsync ( ( ) =>
139
136
{
140
137
cacheSizes [ localPath ] = localSize ;
141
138
@@ -145,7 +142,7 @@ await dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
145
142
folder . FileSize = size . ToSizeString ( ) ;
146
143
RaiseSizeChanged ( folder ) ;
147
144
} ;
148
- } ) ;
145
+ } , Windows . System . DispatcherQueuePriority . Low ) ;
149
146
}
150
147
151
148
if ( cancellationToken . IsCancellationRequested )
0 commit comments