@@ -20,7 +20,7 @@ namespace BatchConvertToCHD;
2020public partial class MainWindow : IDisposable
2121{
2222 private CancellationTokenSource _cts ;
23- private readonly object _ctsLock = new object ( ) ;
23+ private readonly object _ctsLock = new ( ) ;
2424 private readonly string _maxCsoPath ;
2525 private readonly bool _isMaxCsoAvailable ;
2626 private readonly bool _isChdmanAvailable ;
@@ -499,7 +499,7 @@ private void DisplayExtractionInstructionsInLog()
499499
500500 private void MainTabControl_SelectionChanged ( object sender , SelectionChangedEventArgs e )
501501 {
502- if ( e . Source is not TabControl )
502+ if ( e . Source is not TabControl control )
503503 {
504504 return ;
505505 }
@@ -510,7 +510,7 @@ private void MainTabControl_SelectionChanged(object sender, SelectionChangedEven
510510 }
511511
512512 Application . Current . Dispatcher . InvokeAsync ( ( Action ) ( ( ) => LogViewer . Clear ( ) ) ) ;
513- if ( ( ( TabControl ) e . Source ) . SelectedItem is TabItem selectedTab )
513+ if ( control . SelectedItem is TabItem selectedTab )
514514 {
515515 switch ( selectedTab . Name )
516516 {
@@ -691,8 +691,14 @@ private async void StartExtractionButton_ClickAsync(object sender, RoutedEventAr
691691
692692 try
693693 {
694+ CancellationToken token ;
695+ lock ( _ctsLock )
696+ {
697+ token = _cts . Token ;
698+ }
699+
694700 await PerformBatchExtractionAsync ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , AppConfig . ChdmanExeName ) ,
695- inputFolder , outputFolder , deleteOriginal , selectedFiles , _cts . Token ) ;
701+ inputFolder , outputFolder , deleteOriginal , selectedFiles , token ) ;
696702 }
697703 catch ( OperationCanceledException )
698704 {
@@ -1011,8 +1017,14 @@ private async void StartConversionButton_ClickAsync(object sender, RoutedEventAr
10111017
10121018 try
10131019 {
1020+ CancellationToken token ;
1021+ lock ( _ctsLock )
1022+ {
1023+ token = _cts . Token ;
1024+ }
1025+
10141026 await PerformBatchConversionAsync ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , AppConfig . ChdmanExeName ) ,
1015- inputFolder , outputFolder , deleteFiles , processSmallerFirst , forceCd , forceDvd , timeoutMinutes , selectedFiles , _cts . Token ) ;
1027+ inputFolder , outputFolder , deleteFiles , processSmallerFirst , forceCd , forceDvd , timeoutMinutes , selectedFiles , token ) ;
10161028 }
10171029 catch ( OperationCanceledException )
10181030 {
@@ -1078,8 +1090,14 @@ private async void StartVerificationButton_ClickAsync(object sender, RoutedEvent
10781090
10791091 try
10801092 {
1093+ CancellationToken token ;
1094+ lock ( _ctsLock )
1095+ {
1096+ token = _cts . Token ;
1097+ }
1098+
10811099 await PerformBatchVerificationAsync ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , AppConfig . ChdmanExeName ) ,
1082- inputFolder , includeSubfolders , moveSuccess , successFolder , moveFailed , failedFolder , selectedFiles , _cts . Token ) ;
1100+ inputFolder , includeSubfolders , moveSuccess , successFolder , moveFailed , failedFolder , selectedFiles , token ) ;
10831101 }
10841102 catch ( OperationCanceledException )
10851103 {
@@ -1130,6 +1148,7 @@ private void CancelButton_Click(object sender, RoutedEventArgs e)
11301148 {
11311149 _cts . Cancel ( ) ;
11321150 }
1151+
11331152 LogMessage ( "Cancellation requested..." ) ;
11341153 UpdateStatusBarMessage ( "Cancelling..." ) ;
11351154 }
@@ -1496,7 +1515,7 @@ private async Task<bool> ProcessSingleFileForConversionAsync(string chdmanPath,
14961515 break ;
14971516 }
14981517
1499- var missingFiles = filesToCopy . Distinct ( ) . Where ( f => ! File . Exists ( f ) ) . ToList ( ) ;
1518+ var missingFiles = filesToCopy . Distinct ( ) . Where ( static f => ! File . Exists ( f ) ) . ToList ( ) ;
15001519 if ( missingFiles . Count > 0 )
15011520 {
15021521 var missingNames = string . Join ( ", " , missingFiles . Select ( Path . GetFileName ) ) ;
@@ -2715,6 +2734,7 @@ public void Dispose()
27152734 _cts . Cancel ( ) ;
27162735 _cts . Dispose ( ) ;
27172736 }
2737+
27182738 _writeBytesCounter ? . Dispose ( ) ;
27192739 _readBytesCounter ? . Dispose ( ) ;
27202740 _archiveService . Dispose ( ) ;
0 commit comments