protected void bgOutputWorker_DoWork(object sender, DoWorkEventArgs e) { _thHashMonitor.Start(); oWatch.Start(); if (OutputList != null) { while (_thHashMonitor.IsAlive) { if (OutputList.Count > 0) { OutputDataStruct tempResultData = OutputList.Take(); if (tempResultData != null) { System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.DataBind, new Action(() => { _duplicateFilesFound++; DuplicateItemList.Add(tempResultData); //tempResultData.FileName1 + @" <==> " + tempResultData.FileName2); //Console.WriteLine(_duplicateFilesFound + @" Duplicate file(s) found out of " + _totalFilesToScan + @" files."); LblStatus = @" " + _duplicateFilesFound.ToString() + " files found."; Refresh("LblStatus"); })); //_bgOutputWorker.ReportProgress(OutputList.Count, tempResultData); } } } } Console.WriteLine("----" + outputList.Count.ToString()); }
private void StartSearchOperation() { try { InitScanProcess(); _outputFile = OutputFile; string scanDir = SearchDirectory; int scanThreads = NumThreads;// Convert.ToInt32(numUpDownScanThreads.Value); LblStatus = @"Validating input data and initializing..."; Refresh("LblStatus"); //Check if the selected scan directory is still available. if (!Directory.Exists(scanDir)) { //showValidatationMessage(@"Unable to find scan directory", MessageBoxIcon.Warning); return; } DuplicateItemList.Clear(); Refresh("ItemUsers"); //lstBoxResults.Items.Clear(); _scanList = new List <DataStuctInfo>(); LblStatus = @"Scanning directory contents..."; Refresh("LblStatus"); String[] fileList = Directory.GetFiles(scanDir, "*", SearchOption.AllDirectories); _totalFilesToScan = fileList.Length; //Check if the files to scan is greater than the number of allocated threads. if (_totalFilesToScan < scanThreads) { //showValidatationMessage(@"Total files found in the directory is less than the scan thrad count. Please reduce the thread count or select a different direcotory.", MessageBoxIcon.Warning); return; } foreach (string filePath in fileList) { _scanList.Add(new DataStuctInfo(filePath)); } if (_scanList.Count < 2) { //showValidatationMessage(@"Selected directory may not contain enough files to perform matching", MessageBoxIcon.Warning); return; } //Invalidate(); if (File.Exists(_outputFile)) { File.Delete(_outputFile); } LblStatus = @"Start scanning files..."; Refresh("LblStatus"); _threadExecState = new ThreadControl { ThreadPause = false }; //UpdatePauseCaption(); Refresh("IsVisiblilityForSearch"); Refresh("IsVisiblility"); OutputList = new BlockingCollection <OutputDataStruct>(); isOperationStarted = true; mainWindowCommand.RefreshCanExecute(); Refresh("IsVisiblility"); Refresh("IsVisiblilityForSearch"); PerformFileHashUpdate(scanThreads); } catch (Exception ex) { //result = ShowThreadExceptionDialog("Error occured.", ex); //// Exits the program when the user clicks Abort. //if (result == DialogResult.Abort) // Environment.Exit(0); } }