diff --git a/AIDevGallery/Controls/SampleContainer.xaml.cs b/AIDevGallery/Controls/SampleContainer.xaml.cs index bb6b47c5..8739ec91 100644 --- a/AIDevGallery/Controls/SampleContainer.xaml.cs +++ b/AIDevGallery/Controls/SampleContainer.xaml.cs @@ -58,6 +58,7 @@ public List NugetPackageReferences public static readonly DependencyProperty NugetPackageReferencesProperty = DependencyProperty.Register("NugetPackageReferences", typeof(List), typeof(SampleContainer), new PropertyMetadata(null)); + private readonly object _ctsLock = new object(); private RichTextBlockFormatter codeFormatter; private Dictionary codeFiles = new(); private Sample? _sampleCache; @@ -65,7 +66,6 @@ public List NugetPackageReferences private List? _modelsCache; private WinMlSampleOptions? _currentWinMlSampleOptions; private CancellationTokenSource? _sampleLoadingCts; - private readonly object _ctsLock = new object(); private TaskCompletionSource? _sampleLoadedCompletionSource; private double _codePaneWidth; private ModelType? _wcrApi; @@ -119,10 +119,14 @@ private void CancelCTS() if (cts != null) { - using (cts) + try { cts.Cancel(); } + finally + { + cts.Dispose(); + } } }