2

これはばかげているように聞こえるかもしれませんが、別のスレッドのプログレスバーにアクセスできません。はい、呼び出しました。見てみな:

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() を呼び出しています。デバッガーを見てください。

デバッガーのスクリーンショット

ProgressBar は何もしません。これは、databaseHandler クラスのメソッドからサブ updateProgressBarCurrent を呼び出しているためですか? どうすればこれを修正できますか? 前もって感謝します。

4

1 に答える 1

2

Forms の「既定のインスタンス」機能を使用していますか? マルチスレッドアプリではダメ!スレッドごとに 1 つのデフォルト インスタンスがあります。したがってForm1.DoSomething、別のスレッドから呼び出す場合は、「自分の」Form1 を呼び出すのではなく、Form1 の新しい (非表示、表示されていない) インスタンスを呼び出します。

于 2012-11-15T14:17:35.847 に答える