I have the following code in a form called Fetch.vb:
Imports System.ComponentModel ' might not be needed? Imports System.Threading Public Class Fetch Public Sub New() InitializeComponent() backgroundWorker1.WorkerReportsProgress = True backgroundWorker1.WorkerSupportsCancellation = True End Sub Private Sub btnFetch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFetch.Click Dim ctrl As Control For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then If ctrl.Text.Length = (Not 0) Then tbList.Add(ctrl.Text) MsgBox(tbList.Item(0).ToString) Exit For End If End If Next ' ProcessLinks() btnFetch.Enabled = False BackgroundWorker1.RunWorkerAsync() End Sub Public Sub backgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork AddHandler BackgroundWorker1.DoWork, AddressOf backgroundWorker1_DoWork ProcessLinks() End Sub End Class Now process links is a module with a public sub in with the code I am trying to run, I don't need any arguments passed to it, and it doesn't do anything that (I think) could affect this, I think I'm just doing the threading code wrong. I have backgroundworker1 in my fetch.vb form, and when I click btn Fetch, the program does nothing.
Any help and guidance or reading material would be greatly appreciated.
EDIT Here is my LinkProcess module.
Public Module LinkProcess Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles Fetch.BackgroundWorker1.DoWork ProcessLinks() End Sub Public Sub ProcessLinks() Dim tbContent As String For Each tbContent In Fetch.tbList Process.Start(tbContent) Next End Sub End Module
BackgroundWorker.IsBusy, simply disable thebtnFetchbutton (and enable it again once the background work is completed). From a user experience standpoint, it doesn't make sense to have an enabled button that doesn't do anything. 2. Incidentally, this might also remove a potential source of errors; namely, have you verified that.IsBusyis actuallyFalseduring the first button click?