1313using Interacts ;
1414using Windows . UI . Xaml . Controls ;
1515using Windows . UI . Xaml . Media . Animation ;
16+ using System . Threading ;
17+ using System . Threading . Tasks ;
1618
1719namespace ItemListPresenter
1820{
@@ -119,6 +121,46 @@ public static ProgressUIVisibility PVIS
119121 }
120122 }
121123
124+ private ListedItem li = new ListedItem ( ) ;
125+ public ListedItem LI { get { return this . li ; } }
126+
127+ private static ProgressUIHeader pUIh = new ProgressUIHeader ( ) ;
128+ public static ProgressUIHeader PUIH { get { return ItemViewModel . pUIh ; } }
129+
130+ private static ProgressUIPath pUIp = new ProgressUIPath ( ) ;
131+ public static ProgressUIPath PUIP { get { return ItemViewModel . pUIp ; } }
132+
133+ private static ProgressUIButtonText buttonText = new ProgressUIButtonText ( ) ;
134+ public static ProgressUIButtonText ButtonText { get { return ItemViewModel . buttonText ; } }
135+
136+ private static CollisionBoxHeader collisionBoxHeader = new CollisionBoxHeader ( ) ;
137+ public static CollisionBoxHeader CollisionBoxHeader { get { return collisionBoxHeader ; } }
138+
139+ private static CollisionBoxSubHeader collisionBoxSubHeader = new CollisionBoxSubHeader ( ) ;
140+ public static CollisionBoxSubHeader CollisionBoxSubHeader { get { return collisionBoxSubHeader ; } }
141+
142+ private static CollisionUIVisibility collisionUIVisibility = new CollisionUIVisibility ( ) ;
143+ public static CollisionUIVisibility CollisionUIVisibility { get { return collisionUIVisibility ; } }
144+
145+ private static CollisionBoxHeader conflictBoxHeader = new CollisionBoxHeader ( ) ;
146+ public static CollisionBoxHeader ConflictBoxHeader { get { return conflictBoxHeader ; } }
147+
148+ private static CollisionBoxSubHeader conflictBoxSubHeader = new CollisionBoxSubHeader ( ) ;
149+ public static CollisionBoxSubHeader ConflictBoxSubHeader { get { return conflictBoxSubHeader ; } }
150+
151+ private static CollisionUIVisibility conflictUIVisibility = new CollisionUIVisibility ( ) ;
152+ public static CollisionUIVisibility ConflictUIVisibility { get { return conflictUIVisibility ; } }
153+
154+ private static EmptyFolderTextState textState = new EmptyFolderTextState ( ) ;
155+ public static EmptyFolderTextState TextState { get { return textState ; } }
156+
157+ public static int NumOfItems ;
158+ public static int NumItemsRead ;
159+ public static int NumOfFiles ;
160+ public static int NumOfFolders ;
161+ public static CancellationToken token ;
162+ public static CancellationTokenSource tokenSource ;
163+
122164 public ItemViewModel ( string ViewPath , Page p )
123165 {
124166 pageName = p . Name ;
@@ -137,8 +179,10 @@ public ItemViewModel(string ViewPath, Page p)
137179 GenericFileBrowser . P . path = ViewPath ;
138180 FilesAndFolders . Clear ( ) ;
139181 }
140-
141- GetItemsAsync ( ViewPath ) ;
182+
183+ tokenSource = new CancellationTokenSource ( ) ;
184+ token = tokenSource . Token ;
185+ GetItemsAsync ( ViewPath , token ) ;
142186
143187 if ( pageName != "ClassicModePage" )
144188 {
@@ -169,56 +213,21 @@ private async void DisplayConsentDialog()
169213 await message . ShowAsync ( ) ;
170214 }
171215
172- private ListedItem li = new ListedItem ( ) ;
173- public ListedItem LI { get { return this . li ; } }
174-
175- private static ProgressUIHeader pUIh = new ProgressUIHeader ( ) ;
176- public static ProgressUIHeader PUIH { get { return ItemViewModel . pUIh ; } }
177-
178- private static ProgressUIPath pUIp = new ProgressUIPath ( ) ;
179- public static ProgressUIPath PUIP { get { return ItemViewModel . pUIp ; } }
180-
181- private static ProgressUIButtonText buttonText = new ProgressUIButtonText ( ) ;
182- public static ProgressUIButtonText ButtonText { get { return ItemViewModel . buttonText ; } }
183-
184- private static CollisionBoxHeader collisionBoxHeader = new CollisionBoxHeader ( ) ;
185- public static CollisionBoxHeader CollisionBoxHeader { get { return collisionBoxHeader ; } }
186-
187- private static CollisionBoxSubHeader collisionBoxSubHeader = new CollisionBoxSubHeader ( ) ;
188- public static CollisionBoxSubHeader CollisionBoxSubHeader { get { return collisionBoxSubHeader ; } }
189-
190- private static CollisionUIVisibility collisionUIVisibility = new CollisionUIVisibility ( ) ;
191- public static CollisionUIVisibility CollisionUIVisibility { get { return collisionUIVisibility ; } }
192-
193- private static CollisionBoxHeader conflictBoxHeader = new CollisionBoxHeader ( ) ;
194- public static CollisionBoxHeader ConflictBoxHeader { get { return conflictBoxHeader ; } }
195-
196- private static CollisionBoxSubHeader conflictBoxSubHeader = new CollisionBoxSubHeader ( ) ;
197- public static CollisionBoxSubHeader ConflictBoxSubHeader { get { return conflictBoxSubHeader ; } }
198-
199- private static CollisionUIVisibility conflictUIVisibility = new CollisionUIVisibility ( ) ;
200- public static CollisionUIVisibility ConflictUIVisibility { get { return conflictUIVisibility ; } }
201-
202- private static EmptyFolderTextState textState = new EmptyFolderTextState ( ) ;
203- public static EmptyFolderTextState TextState { get { return textState ; } }
204- public static bool IsStopRequested = false ;
205- public static bool IsTerminated = true ;
206-
207- public static int NumOfItems ;
208- public static int NumItemsRead ;
209- public static int NumOfFiles ;
210- public static int NumOfFolders ;
211- public async void GetItemsAsync ( string path )
216+
217+ public async void GetItemsAsync ( string path , CancellationToken token )
212218 {
213219 Stopwatch stopwatch = new Stopwatch ( ) ;
214220 stopwatch . Start ( ) ;
215221
216- IsTerminated = false ;
217222 PUIP . Path = path ;
218223 try
219224 {
220225 folder = await StorageFolder . GetFolderFromPathAsync ( path ) ; // Set location to the current directory specified in path
221226 folderList = await folder . GetFoldersAsync ( ) ; // Create a read-only list of all folders in location
227+ if ( token . IsCancellationRequested == true )
228+ {
229+ return ;
230+ }
222231 fileList = await folder . GetFilesAsync ( ) ; // Create a read-only list of all files in location
223232 NumOfFolders = folderList . Count ; // How many folders are in the list
224233 NumOfFiles = fileList . Count ; // How many files are in the list
@@ -241,10 +250,8 @@ public async void GetItemsAsync(string path)
241250 {
242251 foreach ( StorageFolder fol in folderList )
243252 {
244- if ( IsStopRequested )
253+ if ( token . IsCancellationRequested == true )
245254 {
246- IsStopRequested = false ;
247- IsTerminated = true ;
248255 return ;
249256 }
250257 int ProgressReported = ( NumItemsRead * 100 / NumOfItems ) ;
@@ -276,10 +283,8 @@ public async void GetItemsAsync(string path)
276283 {
277284 foreach ( StorageFile f in fileList )
278285 {
279- if ( IsStopRequested )
286+ if ( token . IsCancellationRequested == true )
280287 {
281- IsStopRequested = false ;
282- IsTerminated = true ;
283288 return ;
284289 }
285290 int ProgressReported = ( NumItemsRead * 100 / NumOfItems ) ;
@@ -336,7 +341,6 @@ public async void GetItemsAsync(string path)
336341 PVIS . isVisible = Visibility . Collapsed ;
337342 }
338343
339- IsTerminated = true ;
340344
341345 }
342346 catch ( UnauthorizedAccessException )
@@ -352,7 +356,7 @@ public async void GetItemsAsync(string path)
352356 }
353357 stopwatch . Stop ( ) ;
354358 Debug . WriteLine ( "Loading of: " + path + " completed in " + stopwatch . ElapsedMilliseconds + " Milliseconds." ) ;
355-
359+
356360 }
357361
358362 public static ProgressPercentage progressPER = new ProgressPercentage ( ) ;
0 commit comments