Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42732

Why my ProgressBar stucks in this code!?

$
0
0
Hi guys!
Please take a look at this code and let me know why the progressbar stucks?
I should notice that I am using a sub which is placed in a module, and the sub is going to read button.text from my UI and change that.
I have 100 buttons on Form1. Sub MosMos read them and changes their names.
And I should say that my ProgressBar is Docked in FormMosWaiting.

Code:

Module M1
    Sub MosMos(ByVal Hs As String, ByVal HsC As Integer)
        'Read and write on all buttons placed on Form1.
    End Sub
End Module


Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Delegate Sub CallMos(ByVal Hs As String, ByVal HsC As Integer)

    Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim Del As CallMos
        For TMP = 1 To 100
            BackgroundWorker1.ReportProgress(TMP)
            Del = New CallMos(AddressOf MosMos)
            Me.Invoke(New Action(Of String, Integer)(AddressOf MosMos), Me.Controls("Button" & TMP).Text, TMP)
        Next TMP
    End Sub

    Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
        Dim LT As Integer = e.ProgressPercentage
        FormMosWaiting.ProgressBarMosWaiting.Value = LT
        FormMosWaiting.LabelPercent.Text = LT & "%"
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        FormMosWaiting.Close()
    End Sub

End Class

I should notice that once I change this line follow bellow. Now I see the ProgressBar doesn't stuck, but changing button.text doesn't work correctly:

Code:

            Del.Invoke(Me.Controls("Button" & TMP).Text, TMP)
Please Help.
Thanks in advance.

Viewing all articles
Browse latest Browse all 42732

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>