private void _worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { FileInfo info = e.UserState as FileInfo; if (info != null) { if (Progress != null) { AnalyzeProgress ap = new AnalyzeProgress(e.ProgressPercentage, info); Progress(this, ap); // _synchronizationContext.Post((o) => Progress(this, ap), null); } FileEntry entry = _controlAnalyzer.ValidateSource(info); if (entry != null) { if (FileEntryAdded != null) { FileEntryChanged fec = new FileEntryChanged(_entryIndex, entry); FileEntryAdded(this, fec); // _synchronizationContext.Post((o) => FileEntryAdded(this, fec), null); } } } }
private void ScanFiles() { lock (thisLock) { _autoEvent.Reset(); AnalyzeResult result = AnalyzeResult.Success; Exception error = null; try { if (string.IsNullOrEmpty(_directory)) { throw new ArgumentNullException(_directory); } if (!Directory.Exists(_directory)) { throw new FileNotFoundException(); } string[] _files; if (_scanSubFolder) { _files = Directory.GetFiles(_directory, "*.*", SearchOption.AllDirectories); } else { _files = Directory.GetFiles(_directory, "*.*"); } _totalFiles = _files.Length; if (_files.Length > 0) { int progress = 0; int entryIndex = 0; foreach (string file in _files) { FileInfo info = new FileInfo(file); if (_autoEvent.WaitOne(0, false)) { result = AnalyzeResult.Cancel; break; } else { if (Progress != null) { AnalyzeProgress ap = new AnalyzeProgress(progress, info); Progress(this, ap); // _synchronizationContext.Post((o) => Progress(this, ap), null); } FileEntry entry = _controlAnalyzer.ValidateSource(info); if (entry != null) { if (FileEntryAdded != null) { FileEntryChanged fec = new FileEntryChanged(entryIndex, entry); FileEntryAdded(this, fec); // _synchronizationContext.Post((o) => FileEntryAdded(this, fec), null); } } } progress++; } } } catch (Exception ex) { result = AnalyzeResult.Error; error = ex; } finally { } if (Completed != null) { AnalyzeCompleted ac = new AnalyzeCompleted(result, error); Completed(this, ac); } } }