예제 #1
0
 public virtual void Begin(MainWindowViewModel viewModel, DataDriveViewModel selectedDrive = null)
 {
     cancelled      = false;
     this.viewModel = viewModel;
     viewModel.ParitySet.ErrorMessage += HandleErrorMessage;
     viewModel.StartProgress();
     startTime  = DateTime.Now;
     inProgress = true;
     drive      = selectedDrive;
     errorMessages.Clear();
     if (ScanFirst && viewModel.Drives.Count > 0)
     {
         scanning         = true;
         viewModel.Status = "Scanning drives...";
         runningScans     = 0;
         scanProgress     = new double[viewModel.Drives.Count];
         foreach (DataDriveViewModel vm in viewModel.Drives)
         {
             if ((scanDrive != null && vm == scanDrive) || (scanDrive == null && vm != skipDrive))
             {
                 Interlocked.Increment(ref runningScans);
                 vm.PropertyChanged         += HandleDataDrivePropertyChanged;
                 vm.DataDrive.ScanCompleted += HandleScanCompleted;
                 vm.Scan(auto); // runs in a separate Task
             }
         }
     }
     else
     {
         Run();
     }
 }
예제 #2
0
        /// <summary>
        /// Runs the actual operation itself in a separate Task
        /// </summary>
        private void Run()
        {
            LogFile.Log("Beginning " + Name);
            if (!PrepareOperation())
            {
                LogFile.Log(Name + " cancelled.");
                Status = Name + " cancelled";
                End();
                return;
            }

            viewModel.StartProgress();
            Status = Name + " in progress...";

            Task.Factory.StartNew(() =>
            {
                try {
                    DoOperation();
                    if (cancelled)
                    {
                        LogFile.Log(Name + " cancelled.");
                        Status = Name + " cancelled.";
                    }
                    else
                    {
                        LogFile.Log(Name + " complete (operation took " + Utils.SmartTime(DateTime.Now - startTime) + ")");
                    }
                }
                catch (Exception e) {
                    App.LogCrash(e);
                    Status = Name + " failed: " + e.Message;
                }
                finally {
                    End();
                }
            });
        }
예제 #3
0
 public virtual void Begin(MainWindowViewModel viewModel, DataDriveViewModel selectedDrive = null)
 {
     cancelled = false;
       this.viewModel = viewModel;
       viewModel.ParitySet.ErrorMessage += HandleErrorMessage;
       viewModel.StartProgress();
       startTime = DateTime.Now;
       inProgress = true;
       drive = selectedDrive;
       errorMessages.Clear();
       if (ScanFirst && viewModel.Drives.Count > 0) {
     scanning = true;
     viewModel.Status = "Scanning drives...";
     runningScans = 0;
     scanProgress = new double[viewModel.Drives.Count];
     foreach (DataDriveViewModel vm in viewModel.Drives)
       if ((scanDrive != null && vm == scanDrive) || (scanDrive == null && vm != skipDrive)) {
     Interlocked.Increment(ref runningScans);
     vm.PropertyChanged += HandleDataDrivePropertyChanged;
     vm.DataDrive.ScanCompleted += HandleScanCompleted;
     vm.Scan(auto); // runs in a separate Task
       }
       }
       else
     Run();
 }