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 8509767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:31:27+00:00 2026-06-11T03:31:27+00:00

Saw this in some code but didn’t make sense to me, So I was

  • 0

Saw this in some code but didn’t make sense to me, So I was wondering if even it is a correct way of utilizing backgreound worker?

it is used like this on Form_Load event:

    BackgroundWorker asyncWorker = new BackgroundWorker();
    asyncWorker.DoWork += new DoWorkEventHandler(AsynchDoWork);
    asyncWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AsynchCompleted);
    asyncWorker.RunWorkerAsync();

   // a for each loop that can take some time to populate a combobx on the form

Also, is there a better alternative on achieving the same goal? other than backgroundworker?

  • 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-06-11T03:31:28+00:00Added an answer on June 11, 2026 at 3:31 am

    I would use the Task Parralell Library for this. A good into tutorial is Task Parallel Library: 1 of n. To update a combo box following the result of some background task you could do something like this

    // Get UI scheduler. Use this to update ui thread in continuation.
    TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
    
    // You can use TPL like this...
    List<object> objList = new List<object>();
    Task<object[]> task = Task.Factory.StartNew<object[]>(() =>
        {
            // Pull all your data into some object.
            object[] objArr = new object[] { "Some", "Stuff", "..." };
            return objArr;
        }, TaskCreationOptions.PreferFairness);
    
    // Continuation firs after the antecedent task is completed.
    task.ContinueWith(ant =>
        {
            // Get returned data set.
            object[] resultSet = (task.Result as object[]);
    
            // Check task status.
            switch (task.Status)
            {
                // Handle any exceptions to prevent UnobservedTaskException.             
                case TaskStatus.RanToCompletion:
                    if (task.Result != null)
                    {
                        // Update UI comboBox.
                    }
                    break;
                default:
                    break;
            }
        }, CancellationToken.None, TaskContinuationOptions.None, uiScheduler);
    

    Here the uiScheduler lets you update the ui thread from within the continuation delegate which fires when the antecedent task completes (either successfully or otherwise).

    The continuation also acts as an exception handler in this case to catch any AggregateExceptions they may be thrown from the background thread.

    I hope this helps.

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

Sidebar

Related Questions

I saw this in some code: $(<p/>).append(<div>something</div>).appendTo(body); and noticed that it automatically closed the
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result,
I was going through some code today and saw this: x.add(getResources().getString(R.string.none)); x.add(getResources().getString(R.string.today)); x.add(getResources().getString(R.string.tomorrow)); ...
I saw a post on this already, but it didn't really provide a solution
I was digging around on some HTML on a webpage and saw this: <!DOCTYPE
I saw this as an example on MDN and didn't understand why this was
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I'm having problems submitting my iphone application. I saw some similar questions, but I
While looking at some Javascript code for Mozilla's (Firefox) Add-on SDK, I saw kind

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.