protected bool ShowProgressPane() { if (ProgressPane != null) { _progressPaneActive = true; return(ProgressPane.Show(new CancelProgressCallback(CancelCurrentExtensionQuery), true)); } else { return(false); } }
public override void WriteProgress(long sourceId, ProgressRecord record) { if (record is null) { throw new ArgumentNullException(nameof(record)); } lock (_instanceLock) { if (_pendingProgress is null) { Debug.Assert(_progPane is null, "If there is no data struct, there shouldn't be a pane, either."); _pendingProgress = new PendingProgress(); } _pendingProgress.Update(sourceId, record); if (_progPane is null) { // This is the first time we've received a progress record, so // - create a progress pane, // - set up a update flag // - create a timer for updating the flag _progPane = new ProgressPane(this); if (_progPaneUpdateTimer is null) { // Show a progress pane at the first time we've received a progress record progPaneUpdateFlag = ToRender; // The timer will be auto restarted every 'UpdateTimerThreshold' ms _progPaneUpdateTimer = new Timer(new TimerCallback(ProgressPaneUpdateTimerElapsed), null, UpdateTimerThreshold, UpdateTimerThreshold); } } if (Interlocked.CompareExchange(ref progPaneUpdateFlag, ToNotRender, ToRender) == ToRender || record.RecordType == ProgressRecordType.Completed) { // Update the progress pane only when the timer set up the update flag or WriteProgress is completed. // As a result, we do not block WriteProgress and whole script and eliminate unnecessary console locks and updates. _progPane.Show(_pendingProgress); } } }