Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6923331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:31:20+00:00 2026-05-27T10:31:20+00:00

I am using the BackgroundWorker to do some heavy stuff in the background so

  • 0

I am using the BackgroundWorker to do some heavy stuff in the background so that the UI does not become unresponsive.

But today I noticed that when I run my program, only one of the two CPUs is being used.

Is there any way to use all CPUs with the BackgroundWorker?

enter image description here

Here is my simplified code, just if you are curious!


private System.ComponentModel.BackgroundWorker bwPatchApplier;

this.bwPatchApplier.WorkerReportsProgress = true;
this.bwPatchApplier.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bwPatchApplier_DoWork);
this.bwPatchApplier.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bwPatchApplier_ProgressChanged);
this.bwPatchApplier.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bwPatchApplier_RunWorkerCompleted);

private void bwPatchApplier_DoWork(object sender, DoWorkEventArgs e)
{
    string pc1WorkflowName;
    string pc2WorkflowName;

    if (!GetWorkflowSettings(out pc1WorkflowName, out pc2WorkflowName)) return;

    int progressPercentage = 0;
    var weWorkspaces = (List<WEWorkspace>) e.Argument;

    foreach (WEWorkspace weWorkspace in weWorkspaces)
    {
        using (var spSite = new SPSite(weWorkspace.SiteId))
        {
            foreach (SPWeb web in spSite.AllWebs)
            {
                using (SPWeb spWeb = spSite.OpenWeb(web.ID))
                {
                    PrintHeader(spWeb.ID, spWeb.Title, spWeb.Url, bwPatchApplier);

                    try
                    {
                        for (int index = 0; index < spWeb.Lists.Count; index++)
                        {
                            SPList spList = spWeb.Lists[index];

                            if (spList.Hidden) continue;

                            string listName = spList.Title;

                            if (listName.Equals("PC1") || listName.Equals("PC2"))
                            {
                                #region STEP 1

                                // STEP 1: Remove Workflow

                                #endregion

                                #region STEP 2

                                // STEP 2: Add Events: Adding & Updating

                                #endregion
                            }

                            if ((uint) spList.BaseTemplate == 10135 || (uint) spList.BaseTemplate == 10134)
                            {
                                #region STEP 3

                                // STEP 3: Configure Custom AssignedToEmail Property

                                #endregion

                                #region STEP 4

                                if (enableAssignToEmail)
                                {
                                    // STEP 4: Install AssignedTo events to Work lists
                                }

                                #endregion
                            }

                            #region STEP 5

                            // STEP 5 Install Notification Events

                            #endregion

                            #region STEP 6

                            // STEP 6 Install Report List Events

                            #endregion

                            progressPercentage += TotalSteps;
                            UpdatePercentage(progressPercentage, bwPatchApplier);
                        }
                    }
                    catch (Exception exception)
                    {
                        progressPercentage += TotalSteps;
                        UpdatePercentage(progressPercentage, bwPatchApplier);
                    }
                }
            }
        }
    }

    PrintMessage(string.Empty, bwPatchApplier);
    PrintMessage("*** Process Completed", bwPatchApplier);

    UpdateStatus("Process Completed", bwPatchApplier);
}

Thanks a lot for looking into this 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:31:21+00:00Added an answer on May 27, 2026 at 10:31 am

    The BackgroundWorker does its work within a single background (ThreadPool) thread. As such, if it’s computationally heavy, it’ll use one CPU heavily. The UI thread is still running on the second, but is probably (like most user interface work) spending almost all of its time idle waiting for input (which is a good thing).

    If you want to split your work up to use more than one CPU, you’ll need to use some other techniques. This could be multiple BackgroundWorker components, each doing some work, or using the ThreadPool directly. Parallel programming has been simplified in .NET 4 via the TPL, which is likely a very good option. For details, you can see my series on the TPL or MSDN’s page on the Task Parallel Library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using System.ComponentModel.BackgroundWorker to execute some longer running task that - in the end
A winforms dialog is using BackgroundWorker to perform some asynchronous operations with significant success.
Say I'm showing the user a form, and using a BackgroundWorker to do some
I'm using BackgroundWorker for the first time, and use is not entirely clear. Can
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I was using a BackgroundWorker to download some web sites by calling WebClient.DownloadString inside
I am using a BackgroundWorker thread to do some work outside of the GUI
I am using a backgroundworker that can have n instances. Problem is the DoWork
I want to display a progress bar while doing some work, but that would
Consider a hypothetical method of an object that does stuff for you: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.