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

  • Home
  • SEARCH
  • 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 7010855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:03:11+00:00 2026-05-27T22:03:11+00:00

I am using the BackgroundWorker to do the heavy tasks so the UI thread

  • 0

I am using the BackgroundWorker to do the heavy tasks so the UI thread doesn’t get blocked. While the BackgroundWorker can send values to the UI thread using the progress-scheme, how can the BackgroundWorker get some values FROM the UI thread?

Either by asking it or simply by the UI thread sending some values to the BackgroundWorker?

Just accessing a variable of the UI thread like UIForm.x within the BackgroundWorker does not work, it does not seem to have access to the UI variables???

Many thanks

  • 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-27T22:03:12+00:00Added an answer on May 27, 2026 at 10:03 pm

    Other threads than the UI thread are not allowed to access the UI. You probably started the BackgroundWorker with worker.RunWorkerAsync(). You can also start it with worker.RunWorkerAsync(someObject). While the worker is running, you cannot pass new objects, but you can alter the contents of the object itself. Since object types are reference types, the UI thread and the worker thread will see the same object content.

    Imports System.ComponentModel
    Imports System.Threading
    
    Class BgWorkerCommunication
        Private _worker As BackgroundWorker
    
        Private Class WorkParameters
            Public text As String
        End Class
    
        Public Sub DoRun()
            Dim param = New WorkParameters()
    
            _worker = New BackgroundWorker()
            AddHandler _worker.DoWork, New DoWorkEventHandler(AddressOf _worker_DoWork)
            AddHandler _worker.RunWorkerCompleted, New RunWorkerCompletedEventHandler(AddressOf _worker_RunWorkerCompleted)
    
            param.text = "running "
            _worker.RunWorkerAsync(param)
            While _worker.IsBusy
                Thread.Sleep(2100)
                param.text += "."
            End While
        End Sub
    
        Private Sub _worker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
            Console.WriteLine("Completed")
        End Sub
    
        Private Sub _worker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
            Dim param = DirectCast(e.Argument, WorkParameters)
            For i As Integer = 0 To 9
                Console.WriteLine(param.text)
                Thread.Sleep(1000)
            Next
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a BackgroundWorker thread to do some work outside of the GUI
I am using the BackgroundWorker to do some heavy stuff in the background so
I'm using BackgroundWorker for the first time, and use is not entirely clear. Can
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
What is the difference between: Starting a new thread Using TPL Using BackgroundWorker All
I was using a BackgroundWorker to download some web sites by calling WebClient.DownloadString inside
I'm using a BackGroundWorker to avoid UI freezing while working with a method which
I am using a backgroundworker that can have n instances. Problem is the DoWork
What is the difference between creating a thead using BackgroundWorker and creating a thread

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.