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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:33:29+00:00 2026-05-30T02:33:29+00:00

Would anyone be able to help me here please. I’m fairly new to VB.net

  • 0

Would anyone be able to help me here please. I’m fairly new to VB.net and threading so im just trying to figure out what is happening.

When I debug this I am getting the error

thread operation not valid: Control ‘ProgressBar1’ accessed from a
thread other than the thread it was created on.

I’m a little lost as to why the error is occuring or how to fix it. I’ve had to put the progress bar in a separate thread otherwise the GUI crashes

Private Sub InstallTheAgent_Click(ByVal sender As System.Object, ByVal e As     System.EventArgs) Handles InstallTheAgent.Click
    MsgBox("Click OK to continue to install the Agent")
    Dim t As Thread

    t = New Threading.Thread(AddressOf WorkInstallAgent)
    t.Start()
End Sub

Private Sub WorkInstallAgent()
    ProgressBarThread()
    Dim DeviceLines As String() = IO.File.ReadAllLines(DynPath & "\machines.txt")
    ProgressBar1.Minimum = 0
    ProgressBar1.Maximum = DeviceLines.Length

    Using myReader As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(DynPath & "\machines.txt")
        ProgressBarThread()
        Do While myReader.Peek() >= 0

            Dim computerName As String = myReader.ReadLine
            If My.Computer.Network.Ping(computerName) = True Then
                Call CopyAgent(computerName)
                Call InstallAgent(computerName)
                Call Agent(computerName)
                Call RemoveTempSoftware(computerName)
            End If
            ProgressBar1.Value = ProgressBar1.Value + 1
        Loop
    End Using

    MsgBox("Installation of the Agent Complete")
    ProgressBar1.Value = 0


End Sub

Public Sub ProgressBar()

    If Me.InvokeRequired Then
        Me.Invoke(New MethodInvoker(AddressOf ProgressBar))
    Else
        Dim DeviceLines As String() = IO.File.ReadAllLines(DynPath & "\machines.txt")
        ProgressBar1.Minimum = 0

        ProgressBar1.Maximum = DeviceLines.Length
    End If
End Sub

Public Sub ProgressBarThread()
    Dim p As Thread

    p = New Threading.Thread(AddressOf ProgressBar)
    p.Start()

End Sub
  • 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-30T02:33:30+00:00Added an answer on May 30, 2026 at 2:33 am

    Progress bar is on GUI thread. If you try to access it form other thread then this error will occur.

    Try usin Background worker. Check this link:
    http://www.java2s.com/Code/VB/GUI/BackgroundWorkerDemo.htm

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

Sidebar

Related Questions

Would anyone be able to tell me how to pull the server name out
could anyone here help me with php an decoding json? Im trying to decode
Would someone be able to help here? I would like to fill a div
I'm trying to figure out a way to create a stored procedure for deleting
I'm trying to do more OOP in Javascript. One thing i can't figure out
I seem to have hit a wall here and would appreciate some help from
Would anyone know if there are plans or extensions to Visual Studio to allow
Would anyone happen to know how to convert type LPTSTR to char * in
Would anyone know what the Win32 equivalent of opendir is (or if it even
Would anyone offer tips, links, code snippets on how to browse to a file

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.