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.
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:
Please Help.
Thanks in advance.
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 ClassCode:
Del.Invoke(Me.Controls("Button" & TMP).Text, TMP)Thanks in advance.