private void OnMatch(SearchLib.Match match, int matchCount) { var fUpdateWordCount = new Action <Match>((m) => { if (!lbTargets.Items.Cast <TargetWord>().Any(w => w.Word.ToLower() == m.Word.ToLower())) { var targetWord = new TargetWord(m.Word, 1); lbTargets.Items.Add(targetWord); } else { for (int i = 0; i < lbTargets.Items.Count; i++) { var targetWord = lbTargets.Items[i] as TargetWord; if (targetWord.Word.ToLower() == m.Word.ToLower()) { targetWord.MatchCount++; lbTargets.Items[i] = targetWord; break; } } } }); if (this.InvokeRequired) { this.Invoke(fUpdateWordCount, match); } else { fUpdateWordCount(match); } // If we have other matches for this file, then append to that set if (_matchResults.ContainsKey(match.File)) { // Get matches for file var fileMatches = _matchResults[match.File]; // Append to it fileMatches.Matches.Add(match); // If we're at the last file and if (_lastFile && _matchResults.All(p => p.Value.MatchCount == p.Value.Matches.Count)) { OnComplete(); } } AddMatchToResults(match, matchCount, true); }
private void OnComplete() { // Remove targets checked listbox items with zero counts InvokeIfRequired((x) => { _suspendFilters = true; for (int i = lbTargets.Items.Count - 1; i >= 0; i--) { TargetWord item = lbTargets.Items[i] as TargetWord; if (item.MatchCount == 0) { lbTargets.Items.RemoveAt(i); } } _suspendFilters = false; }, null); }