protected virtual void BgWorkerDoWork(object sender, DoWorkEventArgs e) { ItemSourceOperation operations = default(ItemSourceOperation); while (this.queuedOperations.Count > 0 && this.perform) { OperationParameters currentParams; if (!this.queuedOperations.TryDequeue(out currentParams)) { System.Threading.Thread.Sleep(100); continue; } this.backgroundWorker.ReportProgress(0, currentParams.Operation); switch (currentParams.Operation) { case ItemSourceOperation.Filtering: this.Filter(currentParams.Descriptors as FilterDescriptorCollection); break; case ItemSourceOperation.Sorting: this.Sort(currentParams.Descriptors as SortDescriptorCollection); break; default: break; } operations |= currentParams.Operation; } e.Result = new ItemSourceOperationCompletedEventArgs(operations, !this.perform); }
public void PerformOperation(ItemSourceOperation operation, IList descriptors, bool force = false) { switch (operation) { case ItemSourceOperation.Filtering: FilterDescriptorCollection filterDescriptors = descriptors as FilterDescriptorCollection; if (this.lastFilterExpression == filterDescriptors.Expression && !force) { return; } this.lastFilterExpression = filterDescriptors.Expression; break; case ItemSourceOperation.Sorting: SortDescriptorCollection sortDescriptors = descriptors as SortDescriptorCollection; if (this.lastSortExpression == sortDescriptors.Expression && !force) { return; } this.lastSortExpression = sortDescriptors.Expression; break; default: break; } OperationParameters operationParams = new OperationParameters(operation, descriptors); this.queuedOperations.Enqueue(operationParams); if (this.backgroundWorker.IsBusy) { OperationParameters peek; bool peeked = this.queuedOperations.TryPeek(out peek); if (peeked && peek.Operation == operationParams.Operation && peek != operationParams) { OperationParameters dequeued; this.queuedOperations.TryDequeue(out dequeued); } else if (peeked && peek.Operation != operationParams.Operation) { this.perform = false; } } if (!this.backgroundWorker.IsBusy) { this.perform = true; this.backgroundWorker.RunWorkerAsync(); this.OnOperationStarted(new ItemSourceOperationEventArgs(operationParams.Operation)); } }
public OperationParameters(ItemSourceOperation operation, IList descriptors) { this.Operation = operation; this.Descriptors = descriptors; }
public ItemSourceOperationCompletedEventArgs(ItemSourceOperation operation, bool canceled) : base(operation) { this.Canceled = canceled; }
public ItemSourceOperationEventArgs(ItemSourceOperation operation) { this.OperationType = operation; }