燮傢伙,線程安全的方法調用不工作
我有我的frmMain類至極一個函數會更新我的控制到調用後別的東西。當我在即時窗口上鍵入「?Label1.Text」時,文本屬性IS會更新,但是當我去檢查窗體時,什麼也沒有發生。該代碼僅僅是這樣
Public Sub UpdateUI()
If (Me.InvokeRequired = True) Then
Invoke(New MethodInvoker(AddressOf UpdateUI))
End If
Label1.Text = "ITS NOT WORKING =\"
End Sub
在我bgWorker類:
Private threadUpd As New Threading.Thread(AddressOf Updater)
Private _active as Boolean
Public Sub New()
_active = True
threadLimpar.IsBackground = True
threadLimpar.Start()
End Sub
Public Sub Updater()
Do
If (_active = False) Then
Try
Thread.Sleep(Timeout.Infinite)
Catch ex As ThreadInterruptedException
End Try
Else
if(condition...) then
frmMain.UpdateUI
End if
Loop
End Sub
我幾乎可以肯定,這是這樣的,但你可以給我一個例子,我是如何引用我已經打開的表單? – Alex 2010-01-02 23:21:29