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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:34:15+00:00 2026-05-29T07:34:15+00:00

I’m trying to thread my functions so the main GUI of my application doesn’t

  • 0

I’m trying to thread my functions so the main GUI of my application doesn’t fail to respond while the tasks are running.

At the moment my form1.vb is something like this. I’ve cut it down as to reduce the text, but everything works fine:

Public Class MAIR

Private Sub InstallTheAgent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InstallTheAgent.Click
    InstallAgentWorker.RunWorkerAsync()
End Sub

Private Sub InstallAgentWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles InstallAgentWorker.DoWork
'Do some stuff
End Sub

Private Sub InstallAgentWorker_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles InstallAgentWorker.RunWorkerCompleted
    ' Called when the BackgroundWorker is completed.
    MsgBox("Installation of the Agent Complete")
    ProgressBar1.Value = 0
End Sub

End Class

From my understanding, when the button “Open” is pressed, it calls the function Install and it should start this off in a separate thread, however this doesn’t work.

This seems to work, but the GUI still locks up, suggesting its not in a separate thread

  • 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-29T07:34:18+00:00Added an answer on May 29, 2026 at 7:34 am

    I recommend using the BackgroundWorker Class to implement this kind of basic threading. You don’t have a lot going on here so the basic implementation should suffice. Here is a snippet of how I would go about doing it. My method is a bit too complex (I have base classes and events wired up to catch a lot of worker events) to list here succinctly, so I’ll abbreviate.

    Public Class MAIR
    
        Dim worker as BackgroundWorker
    
        Private Sub Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
            worker.RunWorkerAsync()
        End Sub
    
        Protected Sub Worker_DoWork(ByVal sender as Object, ByVal e as DoWorkEventArgs)
            Call Shell("psexec.exe", AppWinStyle.Hide, True)       
        End Sub
    
        Protected Sub Worker_ProgressChanged(Byval sender as Object, ByVal e as ProgressChangedEventArgs)
            ' You can track progress reports here if you use them
        End Sub
    
        Protected Sub Worker_RunWorkerCompleted(Byval sender as Object, ByVal e as RunWorkerCompletedEventArgs)
            ' Report back to the main application that the thread is completed
        End Sub
    
        Private Sub Install_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles MyBase.Load
            worker = New BackgroundWorker()
    
            ' Add the event wire-ups
    
            ' ### This event wire-up establishes the link
            ' ### that is used by RunWorkerAsync to initiate
            ' ### the code you want to run asynchronously
            AddHandler worker.DoWork, AddressOf Worker_DoWork
    
            AddHandler worker.ProgressChanged, AddressOf Worker_ProgressChanged
            AddHandler worker.RunWorkerCompleted, AddressOf Worker_RunWorkerCompleted
        End Sub
    
    End Class
    

    This is all translated from C#, so treat it as psuedo-code. The important piece is the documentation of the BackgroundWorker and its behaviors. There is a lot of terrific functionality in this class that takes the headaches of threads away for simple usages. This class is located in System.ComponentModel so you’ll need the reference and an Imports statement.

    Edit: Something I forgot to mention is that once the worker is fired asynchronously, the only manner of tracking it or communicating with the main application is through the ProgressChanged and RunWorkerCompleted events. No global variables or cross-thread items will be available, so you’ll have to use the built-in properties to pass in any values (such as computerName it looks like) that you may need during the run.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.