2012-11-15 71 views
2

這聽起來很愚蠢,但我無法訪問另一個線程中的進度條。是的,我調用了它。檢查出來:通過線程訪問ProgressBar

Delegate Sub ProgressBarCallback(ByVal value As Integer, ByVal max As Integer) 


Sub updateProgressBarCurrent(ByVal value As Integer, ByVal max As Integer) 

    If Me.progressBar_currentState.InvokeRequired = True Then 
     Dim d As New ProgressBarCallback(AddressOf updateProgressBarCurrent) 
     Me.progressBar_currentState.Invoke(d, New Object() {value, max}) 
    Else 
     progressBar_currentState.Maximum = max 
     If value < max Then 
      progressBar_currentState.Value = value 
      progressBar_currentState.Refresh() 
     End If 
    End If 

End Sub 

我從類內的方法調用updateProgressBarCurrent()。看看調試器:

Debugger Screenshot

的進度只是沒有做任何事情。這是因爲我從我的databaseHandler類中的方法調用子updateProgressBarCurrent?我怎樣才能解決這個問題? 在此先感謝。

回答

2

您是否使用Forms的「默認實例」功能?多線程應用程序中的No-Go! 每個線程都有一個默認實例。因此,如果您從另一個線程調用Form1.DoSomething,則不會調用「您的」Form1,而是調用Form1的新(不可見,未顯示)實例。

+0

哎呀,完全忘了那個。非常感謝! – dislick