@@ -51,7 +51,7 @@ public class ItemViewModel : ObservableObject, IDisposable
51
51
private readonly ConcurrentQueue < ( uint Action , string FileName ) > operationQueue ;
52
52
private readonly ConcurrentDictionary < string , bool > itemLoadQueue ;
53
53
private readonly AsyncManualResetEvent operationEvent ;
54
- private IAsyncAction aProcessQueueAction ;
54
+ private Task aProcessQueueAction ;
55
55
56
56
// files and folders list for manipulating
57
57
private List < ListedItem > filesAndFolders ;
@@ -1338,12 +1338,7 @@ private void AssignDefaultIcons()
1338
1338
1339
1339
public void CloseWatcher ( )
1340
1340
{
1341
- if ( aProcessQueueAction != null )
1342
- {
1343
- aProcessQueueAction ? . Cancel ( ) ;
1344
- aProcessQueueAction = null ; // Prevent duplicate execution of this block
1345
- Debug . WriteLine ( "process queue canceled" ) ;
1346
- }
1341
+ aProcessQueueAction = null ;
1347
1342
watcherCTS ? . Cancel ( ) ;
1348
1343
watcherCTS = new CancellationTokenSource ( ) ;
1349
1344
}
@@ -1794,7 +1789,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
1794
1789
1795
1790
if ( aProcessQueueAction == null ) // Only start one ProcessOperationQueue
1796
1791
{
1797
- aProcessQueueAction = Windows . System . Threading . ThreadPool . RunAsync ( ( x ) => ProcessOperationQueue ( x , hasSyncStatus ) ) ;
1792
+ aProcessQueueAction = Task . Run ( ( ) => ProcessOperationQueue ( watcherCTS . Token , hasSyncStatus ) ) ;
1798
1793
}
1799
1794
1800
1795
var aWatcherAction = Windows . System . Threading . ThreadPool . RunAsync ( ( x ) =>
@@ -1893,7 +1888,7 @@ private void WatchForDirectoryChanges(string path, CloudDriveSyncStatus syncStat
1893
1888
} ) ;
1894
1889
}
1895
1890
1896
- private async void ProcessOperationQueue ( IAsyncAction action , bool hasSyncStatus )
1891
+ private async Task ProcessOperationQueue ( CancellationToken cancellationToken , bool hasSyncStatus )
1897
1892
{
1898
1893
ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
1899
1894
string returnformat = Enum . Parse < TimeStyle > ( localSettings . Values [ Constants . LocalSettings . DateTimeFormat ] . ToString ( ) ) == TimeStyle . Application ? "D" : "g" ;
@@ -1910,18 +1905,19 @@ private async void ProcessOperationQueue(IAsyncAction action, bool hasSyncStatus
1910
1905
1911
1906
bool anyEdits = false ;
1912
1907
ListedItem lastItemAdded = null ;
1908
+ var rand = Guid . NewGuid ( ) ;
1913
1909
1914
1910
try
1915
1911
{
1916
- while ( action . Status != AsyncStatus . Canceled )
1912
+ while ( ! cancellationToken . IsCancellationRequested )
1917
1913
{
1918
- if ( await operationEvent . WaitAsync ( 200 ) )
1914
+ if ( await operationEvent . WaitAsync ( 200 , cancellationToken ) )
1919
1915
{
1920
1916
operationEvent . Reset ( ) ;
1921
1917
1922
1918
while ( operationQueue . TryDequeue ( out var operation ) )
1923
1919
{
1924
- if ( action . Status == AsyncStatus . Canceled ) break ;
1920
+ if ( cancellationToken . IsCancellationRequested ) break ;
1925
1921
try
1926
1922
{
1927
1923
switch ( operation . Action )
@@ -2007,6 +2003,8 @@ private async void ProcessOperationQueue(IAsyncAction action, bool hasSyncStatus
2007
2003
{
2008
2004
// Prevent disposed cancellation token
2009
2005
}
2006
+
2007
+ Debug . WriteLine ( "aProcessQueueAction done: {0}" , rand ) ;
2010
2008
}
2011
2009
2012
2010
public ListedItem AddFileOrFolderFromShellFile ( ShellFileItem item , string dateReturnFormat = null )
0 commit comments