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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:43:21+00:00 2026-05-31T13:43:21+00:00

I used BackgroundWorker to solve a problem in my winforms application, I wanted to

  • 0

I used BackgroundWorker to solve a problem in my winforms application, I wanted to be able to cancel a long-running operation and see results live in ListBox while executing the operation. It works fine except when I want to add a checkbox with additional condition.
The problem is when I want to run several operation at once. Ex. both XX and YY executing XX first and then start with YY in that order.

Private Sub UpdateDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestAll.Click
       If cbxTestYY.Checked OrElse cbxTesteXX.Checked Then
        SetBusyState(True)

           If cbxTestXX.Checked Then
             bkWorker.RunWorkerAsync(1)
           End If
           If cbxTesteYY.Checked Then
             bkWorker.RunWorkerAsync(2)
           End If
       End If
End Sub


Private Sub bkWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bkWorker.DoWork
    If bkWorker.CancellationPending Then
         e.Cancel = True
         Exit Sub
      Else
         If e.Argument = 1 Then
            AddItemToListBox("", "XX")
            TestUnits(_XXDimensionUnits, True)
            AddItemToListBox("    Calculating Units     ")
            TestUnits(_XXCalculationUnits, False)
         End If
         If e.Argument = 2 Then
            AddItemToListBox("", "YY")
            TestUnits(_YYCalculationUnits, False)
         End If
      End If
End Sub

I know I am trying to run multiple tasks on same backgroundworker which is not allowed, but I dont have any idea how to solve this so it runs in specific order.
Appriciate all help !!

  • 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-31T13:43:22+00:00Added an answer on May 31, 2026 at 1:43 pm

    Just tell the worker what tests it needs to perform. Start this with an enumeration that declares the tests:

    <Flags()> _
    Private Enum TestsToPerform
        None   = 0
        TestXX = 1
        TestYY = 2
        TestZZ = 4  '' etc, note the value.  Next are 8, 16, 32, 64 etc.
    End Enum
    

    And start the tests like this:

        Dim tests As TestsToPerform = TestsToPerform.None
        If cbxTestXX.Checked Then tests = tests Or TestsToPerform.TestXX
        If cbxTestYY.Checked Then tests = tests Or TestsToPerform.TestYY
        If cbxTestZZ.Checked Then tests = tests Or TestsToPerform.TestZZ
        If tests <> TestsToPerform.None Then
            SetBusyState(True)
            bkWorker.RunWorkerAsync(tests)
        End If
    

    And adjust the code in the worker to test the passed argument for each test:

        Dim tests As TestsToPerform = DirectCast(e.Argument, TestsToPerform)
        If tests And TestsToPerform.TestXX Then
            '' do test xx
        End If
        If tests And TestsToPerform.TestYY Then
            '' do test yy
        End If        
        '' etc..
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application used BackgroundWorker for uploading a file to FTP server. Everything works ok
Never used a cache like this before. The problem is that I want to
I used to be able to do the following in Preview 3 <%=Html.BuildUrlFromExpression<AController>(c =>
Are backgroundworker threads re-used? Specifically, if I set a named data slot (thread-local storage)
My C# application is such that a background worker is being used to wait
I want to write my first real MultiThreaded C# Application. While I used a
I've used BackgroundWorkers quite a bit, but I've never experienced this problem before. My
In my application, I used to create along string of async operations, which passed
In my Silverlight application, I have an operation that takes a couple seconds and
I am using a BackgroundWorker a bit differently than I was used to. Usually,

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.