我已經在形式下面的代碼名爲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
現在工藝環節是與我試圖運行的代碼公共子模塊,我不需要通過任何參數它並沒有做任何(我認爲)會影響到這一點,我想我只是在做錯誤的線程代碼。我在我的fetch.vb表單中有backgroundworker1,當我點擊btn Fetch時,程序什麼都不做。
任何幫助和指導或閱讀材料將不勝感激。
編輯這是我的LinkProcess模塊。
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
** 1。離題建議:不要檢查'BackgroundWorker.IsBusy',只需禁用'btnFetch'按鈕(並在後臺工作完成後再次啓用它)。從用戶體驗的角度來看,啓用不起任何作用的按鈕是沒有意義的。 ** 2。順便說一句,這也可能會消除潛在的錯誤來源;也就是說,在第一次按鈕點擊過程中,你是否證實'.IsBusy'實際上是'False'? – stakx
感謝您的建議,我會馬上這樣做。 – SCGB