// update progress bar thread safe private void UpdateProgressBar(object o, TaskProgressedEventArgs e) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (statusStrip1.InvokeRequired) { //create new delegate UpdateProgressBarDelegate d = new UpdateProgressBarDelegate(UpdateProgressBar);// use the very same function to call it again in correct and save thread this.Invoke(d, new object[] { o, e }); } else { if (e.ProgressIncrement != 0) { toolStripProgressBar1.Increment(1); } else { toolStripProgressBar1.Minimum = (int)e.Start; toolStripProgressBar1.Maximum = (int)e.End; toolStripProgressBar1.Value = (int)e.Val; toolStripStatusLabel1.Text = string.IsNullOrEmpty(e.Text) ? CertFolderStatusStrip: e.Text; } } }
protected virtual void OnTaskProgressed(TaskProgressedEventArgs e) { TaskProgressed?.Invoke(this, e); }