Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recommend using the <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" rel="nofollow">BackgroundWorker Class</a> 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.</p> <pre><code>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 </code></pre> <p>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 <code>System.ComponentModel</code> so you'll need the reference and an <code>Imports</code> statement.</p> <p><strong>Edit:</strong> 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 <code>ProgressChanged</code> and <code>RunWorkerCompleted</code> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload