I am creating a small App with UI on VB.Net (VisualStudio 2010 Ultimate). In this App i am doing mainly math jobs. The main goal is to keep it fast as possible even processing large amounts of data, alright.
I have so far the main Form and a Module, on which i do the calculations, because i think the code on the Module can process things faster and on my Form Class i do the job for the UI.
For example i have declared a Public 'Long' variable on the Module and there is the Sub too which does the calculations, which is triggered by an excecution of a Thread. All runs fine the Long variable holds the right value generated by the Sub via a DO ... Loop Until Boolean.
But when i try to display this value on a Label, it frozed the whole UI til end. Now i resolved the problem with the freezing, but yet the Label.Text itself freezes when it comes to display current values of that variable, only at the end it refreshes. I still dont find a solution for this. The Delegate method seems not to work, Application.DoEvents() is time consuming and it neither works for me, BackgroundWorker, i dont really understand this hack.
Obviously it seems that multiple controls are trying to have access to a certain control, for this causes instability and freeze. Any idea please let me know, thank you
Below you see some snippets of my code on which the problem should lie;
The varibale counter is located on the Module, which is updated by a Thread and which works like a charm, all the other code below is on the Form Class
I need this to give the User ability to follow the progress of certain procedures, in some cases i will update the Label.Text less that in realtime to avoid ages of procedures.
Public counter As Long = 0 ' generated by Do-Loop<...> Statement
Private Delegate Sub UpdateLabelDelegate(ByVal text As String)
' Goal is to display the value of the Long variable 'counter'
Private Sub lbUpdater(ByVal text As String)
If lbProgress.InvokeRequired Then
lbProgress.Invoke(New UpdateLabelDelegate(AddressOf lbUpdater), text)
Else
lbProgress.Text = text
End If
End Sub
Private Sub refresher()
Do While finished = False
lbUpdater(counter.ToString)
Loop
endThread()
End Sub
Dim t As New System.Threading.Thread(AddressOf refresher)
Public Sub startThread()
t.Start()
End Sub
Public Sub endThread()
t.Abort()
End Sub