public void RemovePeaks(SrmDocument.DOCUMENT_TYPE docType, BoundDataGridView dataGridView) { var parent = FormUtil.FindTopLevelOwner(dataGridView); var selectedPeaks = GetSelectedPeaks(dataGridView).Distinct().ToArray(); if (selectedPeaks.Length == 0) { MessageDlg.Show(parent, Resources.RemovePeaksAction_RemovePeaks_No_peaks_are_selected); return; } var lookup = selectedPeaks.ToLookup(tuple => tuple.Item1, tuple => tuple.Item2).ToArray(); string message = GetConfirmRemoveMessage(docType, selectedPeaks.Length, lookup.Length); if (MultiButtonMsgDlg.Show(parent, message, MultiButtonMsgDlg.BUTTON_OK) != DialogResult.OK) { return; } var skylineWindow = GetSkylineWindow(dataGridView); lock (skylineWindow.GetDocumentChangeLock()) { skylineWindow.ModifyDocument(Resources.RemovePeaksAction_RemovePeaks_Remove_peaks, doc => { var longOperationRunner = new LongOperationRunner { ParentControl = parent, JobTitle = Resources.RemovePeaksAction_RemovePeaks_Removing_Peaks }; SrmDocument resultDocument = doc; doc = doc.BeginDeferSettingsChanges(); longOperationRunner.Run(broker => { for (int iGroup = 0; iGroup < lookup.Length; iGroup++) { broker.ProgressValue = iGroup * 100 / lookup.Length; if (broker.IsCanceled) { return; } doc = RemovePeaks(doc, lookup[iGroup]); } resultDocument = doc.EndDeferSettingsChanges(resultDocument, null); }); return(resultDocument); }, docPair => AuditLogEntry.CreateSingleMessageEntry( new MessageInfo(MessageType.removed_peaks, docPair.NewDocumentType, selectedPeaks.Length, lookup.Length))); } }
public override bool RunOnThisThread(Control owner, Action <CancellationToken, IProgressMonitor> job) { var longOperationRunner = new LongOperationRunner(); bool finished = false; longOperationRunner.Run(longWaitBroker => { var progressWaitBroker = new ProgressWaitBroker(progressMonitor => job(longWaitBroker.CancellationToken, progressMonitor)); progressWaitBroker.PerformWork(longWaitBroker); finished = !longWaitBroker.IsCanceled; }); return(finished); }