/// <summary> /// Processes content, first checking if content is valid, then running processing on background thread /// </summary> /// <param name="content"></param> public void Process(List <IContent> content) { // process each content item content.ForEach(singleContentItem => { // check that the item can be processed by this processor if (CanProcess(singleContentItem.GetType())) { // check if processor is already running a diff item if (ProcessWorker.IsBusy) { // lock queue and add item lock (QueueLock) { ContentQueue.Enqueue(singleContentItem); } } else { // process item on background thread ProcessWorker.RunWorkerAsync(singleContentItem); } } }); }
private void binApplyBtn_Click(object sender, EventArgs e) { label4.Text = "Status : Processing!"; if (!ProcessWorker.IsBusy) { ProcessWorker.RunWorkerAsync(); } { MessageBox.Show("Kindly Wait!"); } }
void ProcessWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { OnCompleted(e); lock (QueueLock) { if (ContentQueue.Count > 0) { ProcessWorker.RunWorkerAsync(ContentQueue.Dequeue()); } } }
private void numericUpDown1_ValueChanged(object sender, EventArgs e) { holderTb_1.Text = numericUpDown1.Value.ToString(); if (!ProcessWorker.IsBusy) { label4.Text = "Status : Processing!"; ProcessWorker.RunWorkerAsync(); } else { MessageBox.Show("Kindly Wait!"); } }
/// <summary> /// Handles completion of background processing of an item /// </summary> /// <param name="sender">The worker that has completed</param> /// <param name="e">The completion event args</param> void ProcessWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // allow derived processing of completion of an item OnCompleted(e); // get th next item on the queue, if any lock (QueueLock) { if (ContentQueue.Count > 0) { ProcessWorker.RunWorkerAsync(ContentQueue.Dequeue()); } } }
private void OnActionButtonClicked(object sender, EventArgs e) { switch (ActionButton.Text) { case "Start": SourceGroupBox.Enabled = false; PreferenceGroupBox.Enabled = false; ActionButton.Text = "Cancel"; ProcessWorker.RunWorkerAsync(GetTask()); break; case "Cancel": Application.Exit(); break; case "Close": this.Close(); break; } }
private void WaitingForm_Load(object sender, EventArgs e) { Theme.ChangeFormTheme(this); Icon = Properties.Resources.Revision_Program; ProcessWorker.RunWorkerAsync(); }