/// <summary> /// The method responsible for the filter operation /// </summary> private void FilterThreadMethod() { //block anew new threads from starting _filterWorkerEvent.Reset(); //reset the stopRequested flag _stopRequested = false; FilterTaskQueue taskQueue = new FilterTaskQueue(); //clear all the rows and re-add them, unfortunately due to performance issues //in DataGridView we can't just hide rows _list.Invoke((MethodInvoker) delegate { _list.ClearAllRows(); }); TVRequestInfo header; int currIndex = -1; //calculate visibility and re-add to the list while ((header = _list.DataSource.GetNext(ref currIndex)) != null) { if (_stopRequested) { break; } taskQueue.Enqueue(header); if (taskQueue.Count >= FILTER_EVENTS_QUEUE_SIZE) { Display(taskQueue); } } //drain remaining requests if (taskQueue.Count > 0 && !_stopRequested) { Display(taskQueue); } //allow new threads to start _filterWorkerEvent.Set(); }