Skip to content

Commit 3a68394

Browse files
authored
Fix ObjectDisposedException in CancellationTokenSource (#3580)
1 parent a903f55 commit 3a68394

File tree

3 files changed

+4
-18
lines changed

3 files changed

+4
-18
lines changed

Files/Files.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@
170170
<Compile Include="Converters\UInt32ToString.cs" />
171171
<Compile Include="Converters\VisiblityInvertConverter.cs" />
172172
<Compile Include="Converters\LayoutModeToBoolConverter.cs" />
173-
<Compile Include="Converters\LayoutModeToBoolConverter.cs" />
174173
<Compile Include="DataModels\ShellNewEntry.cs" />
175174
<Compile Include="Dialogs\DynamicDialog.xaml.cs">
176175
<DependentUpon>DynamicDialog.xaml</DependentUpon>

Files/ViewModels/ItemViewModel.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ public void CancelLoadAndClearFiles()
476476
public void CancelExtendedPropertiesLoading()
477477
{
478478
loadPropsCTS.Cancel();
479-
loadPropsCTS.Dispose();
480479
loadPropsCTS = new CancellationTokenSource();
481480
}
482481

@@ -753,7 +752,7 @@ await Task.Run(async () =>
753752
{
754753
await loadExtendedPropsSemaphore.WaitAsync(loadPropsCTS.Token);
755754
}
756-
catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException)
755+
catch (OperationCanceledException)
757756
{
758757
return;
759758
}
@@ -912,7 +911,7 @@ public async void RapidAddItemsToCollectionAsync(string path, string previousDir
912911
// simply drop this instance
913912
await enumFolderSemaphore.WaitAsync(semaphoreCTS.Token);
914913
}
915-
catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException)
914+
catch (OperationCanceledException)
916915
{
917916
return;
918917
}
@@ -921,7 +920,6 @@ public async void RapidAddItemsToCollectionAsync(string path, string previousDir
921920
{
922921
// Drop all the other waiting instances
923922
semaphoreCTS.Cancel();
924-
semaphoreCTS.Dispose();
925923
semaphoreCTS = new CancellationTokenSource();
926924

927925
IsLoadingItems = true;
@@ -1028,7 +1026,6 @@ await folders.AsyncParallelForEach(async (folder) =>
10281026

10291027
if (addFilesCTS.IsCancellationRequested)
10301028
{
1031-
addFilesCTS.Dispose();
10321029
addFilesCTS = new CancellationTokenSource();
10331030
IsLoadingItems = false;
10341031
return;
@@ -1080,10 +1077,6 @@ await folders.AsyncParallelForEach(async (folder) =>
10801077
}
10811078
}
10821079
}
1083-
catch (ObjectDisposedException ex)
1084-
{
1085-
NLog.LogManager.GetCurrentClassLogger().Warn(ex, ex.Message);
1086-
}
10871080
finally
10881081
{
10891082
enumFolderSemaphore.Release();
@@ -1605,7 +1598,6 @@ private void WatchForDirectoryChanges(string path)
16051598
CloseHandle(overlapped.hEvent);
16061599
operationQueue.Clear();
16071600
cts.Cancel();
1608-
cts.Dispose();
16091601
Debug.WriteLine("aWatcherAction done: {0}", rand);
16101602
});
16111603

@@ -1835,7 +1827,7 @@ private async Task UpdateFileOrFolderAsync(string path)
18351827
{
18361828
await enumFolderSemaphore.WaitAsync(semaphoreCTS.Token);
18371829
}
1838-
catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException)
1830+
catch (OperationCanceledException)
18391831
{
18401832
return;
18411833
}
@@ -1880,7 +1872,7 @@ public async Task RemoveFileOrFolderAsync(string path)
18801872
{
18811873
await enumFolderSemaphore.WaitAsync(semaphoreCTS.Token);
18821874
}
1883-
catch (Exception ex) when (ex is OperationCanceledException || ex is ObjectDisposedException)
1875+
catch (OperationCanceledException)
18841876
{
18851877
return;
18861878
}
@@ -1924,9 +1916,6 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
19241916
public void Dispose()
19251917
{
19261918
CancelLoadAndClearFiles();
1927-
addFilesCTS?.Dispose();
1928-
semaphoreCTS?.Dispose();
1929-
loadPropsCTS?.Dispose();
19301919
}
19311920
}
19321921

Files/Views/Pages/Properties.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ private void Properties_Consolidated(ApplicationView sender, ApplicationViewCons
128128
if (tokenSource != null && !tokenSource.IsCancellationRequested)
129129
{
130130
tokenSource.Cancel();
131-
tokenSource.Dispose();
132131
tokenSource = null;
133132
}
134133
}
@@ -141,7 +140,6 @@ private void PropertiesDialog_Closed(ContentDialog sender, ContentDialogClosedEv
141140
if (tokenSource != null && !tokenSource.IsCancellationRequested)
142141
{
143142
tokenSource.Cancel();
144-
tokenSource.Dispose();
145143
tokenSource = null;
146144
}
147145
propertiesDialog.Hide();

0 commit comments

Comments
 (0)