Thread Safe and ProgressBar

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
I am trying to set the ProgressBar.Value to ProgressBar.Maximum >>> Me.ProgressBar.Value = Me.ProgressBar.Maximum
I use this in a thread safe:
Visual Basic:
    Private Delegate Sub SetFullPrgressCallback()
    Private Sub SetFullPrgress()
        If Me.ProgressBar.InvokeRequired Then
            Dim d As New SetFullPrgressCallback(AddressOf SetFullPrgress)
            Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})
        Else
            Me.ProgressBar.Value = Me.ProgressBar.Maximum
        End If
    End Sub
But I get error, and am not able to troobleshot myself, any help?
 
Delegate parameters

Your delegate SetFullPrgressCallback does not take any parameters, so you should not be passing any:

Visual Basic:
Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})
'becomes:
Me.Invoke(d)

Good luck :cool:
 
Thank you so much dear friend for all your helps:)
Sorry to take your valuable time, just let me ask my last question:
If I am going to increase the .Value one unit each time:
Visual Basic:
    Private Delegate Sub SetIncreasePrgressCallback()
    Private Sub SetIncreasePrgress()
        If Me.ProgressBar.InvokeRequired Then
            Dim d As New SetIncreasePrgressCallback(AddressOf SetIncreasePrgress)
            Me.Invoke(d, New Object() {Me.ProgressBar.Value + 1})
        Else
            Me.ProgressBar.Value = Me.ProgressBar.Value + 1
        End If
    End Sub
Where am I wrong?
Thanks.
 
For starters, you are going to need to change your delegate and method so that they take an argument.

Visual Basic:
Private Delegate Sub SetIncreasePrgressCallback(byval value as Integer)
and
Visual Basic:
Private Sub SetIncreasePrgress(byval value as Integer)
My recommendation is to do the following when setting your progress bar's value:
Visual Basic:
Me.ProgressBar.Value = value
As you can see, it is now trivial to combine the two methods you have mentioned into one pretty easily if you wanted to. Now instead of
Visual Basic:
Me.Invoke(d, New Object() {Me.ProgressBar.Value + 1})
' or
Me.Invoke(d, New Object() {Me.ProgressBar.Maximum})
you will only have
Visual Basic:
Me.Invoke(d, New Object() {value})
When you call the method you will pass in either Me.ProgressBar.Maximum or Me.ProgressBar.Value + 1 to this new method that can take any value and set the progress bar accordingly.
 
Back
Top