Пример #1
0
        private async void BTNCompare_Click(object sender, RoutedEventArgs e)
        {
            using (DirectoryComparer comparer = new DirectoryComparer())
            {
                comparer.OnProgressUpdated += comparer_OnProgressUpdated;
                //comparer.OnLogMessage += comparer_OnLogMessage;
                LBLLog.Content = string.Empty;

                Thread timeSpentCounter = new Thread(UpdateTimeElapsed);
                timeSpentCounter.IsBackground = true;
                timeSpentCounter.Priority = ThreadPriority.Lowest;
                timeSpentCounter.Start();

                CompareProgressBar.Visibility = System.Windows.Visibility.Visible;
                BTNCompare.Visibility = System.Windows.Visibility.Hidden;
                BTNStopCompare.Visibility = System.Windows.Visibility.Visible;

                comparer_OnProgressUpdated(null, 0);
                LBLLog.Content = "";

                TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
                TaskbarItemInfo.ProgressValue = 0;

                CancellationTokenSource cts = new CancellationTokenSource();
                RoutedEventHandler cancelHandler = (obj, args) =>
                {
                    cts.Cancel();
                };
                BTNStopCompare.Click += cancelHandler;

                //comparer.HandleFileOperationRequestsAutomatically();

                Stopwatch sw = new Stopwatch();
                try
                {
                    sw.Start();
                    await comparer.CompareAsync(masterDir, secondDir, cts.Token);
                }
                catch(TaskCanceledException)
                {
                    CompareProgressBar.Value = 1;
                    comparer_OnLogMessage(null, "Comparing cancelled");
                }
                finally
                {
                    sw.Stop();

                    BTNStopCompare.Click -= cancelHandler;

                    BTNStopCompare.Visibility = System.Windows.Visibility.Hidden;
                    BTNCompare.Visibility = System.Windows.Visibility.Visible;

                    TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
                }

                timeSpentCounter.Abort();

                BTNCompare.IsEnabled = true;
            }
        }
Пример #2
0
        private async void BTNCompare_Click(object sender, RoutedEventArgs e)
        {
            using (DirectoryComparer comparer = new DirectoryComparer())
            {
                comparer.OnProgressUpdated += comparer_OnProgressUpdated;
                //comparer.OnLogMessage += comparer_OnLogMessage;
                LBLLog.Content = string.Empty;

                Thread timeSpentCounter = new Thread(UpdateTimeElapsed);
                timeSpentCounter.IsBackground = true;
                timeSpentCounter.Priority     = ThreadPriority.Lowest;
                timeSpentCounter.Start();

                CompareProgressBar.Visibility = System.Windows.Visibility.Visible;
                BTNCompare.Visibility         = System.Windows.Visibility.Hidden;
                BTNStopCompare.Visibility     = System.Windows.Visibility.Visible;

                comparer_OnProgressUpdated(null, 0);
                LBLLog.Content = "";

                TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
                TaskbarItemInfo.ProgressValue = 0;

                CancellationTokenSource cts           = new CancellationTokenSource();
                RoutedEventHandler      cancelHandler = (obj, args) =>
                {
                    cts.Cancel();
                };
                BTNStopCompare.Click += cancelHandler;

                //comparer.HandleFileOperationRequestsAutomatically();

                Stopwatch sw = new Stopwatch();
                try
                {
                    sw.Start();
                    await comparer.CompareAsync(masterDir, secondDir, cts.Token);
                }
                catch (TaskCanceledException)
                {
                    CompareProgressBar.Value = 1;
                    comparer_OnLogMessage(null, "Comparing cancelled");
                }
                finally
                {
                    sw.Stop();

                    BTNStopCompare.Click -= cancelHandler;

                    BTNStopCompare.Visibility = System.Windows.Visibility.Hidden;
                    BTNCompare.Visibility     = System.Windows.Visibility.Visible;

                    TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
                }

                timeSpentCounter.Abort();

                BTNCompare.IsEnabled = true;
            }
        }