public void Refresh(string searchLine) { try { if (string.IsNullOrEmpty(searchLine)) { if (_backList.IsEmpty || _backList.Count != MainList.Count) { _backList.Clear(); AddRange(MainList); } } else { _backList.Clear(); var str = searchLine.ToUpper(); List <T> firstList = MainList.AsParallel().Where(_ => _.UpperString.Contains(str)).ToList(); Dictionary <int, List <T> > dict = new Dictionary <int, List <T> >(); foreach (var item in firstList) { var idx = item.UpperString.IndexOf(searchLine, 0, StringComparison.CurrentCultureIgnoreCase); if (!dict.ContainsKey(idx)) { dict.Add(idx, new List <T>() { item }); } else { dict[idx].Add(item); } } for (var i = 0; i < dict.Count; i++) { if (dict.ContainsKey(i)) { AddRange(dict[i]); } } } } catch { // Logging.Log.Write(ex); } oldSearchLine = searchLine; }