I am studying VB.NET and threading.
I tried thread method to dynamically update status on GUI part.
However, GUI randomly freeze after 10-20 mins running.
I am not sure what i missing.
On form1 : I have textbox and label to update on GUI
Imports System.IO
Imports System.Threading
Public Class form1
package.add("sleep_time",3)
Private Sub BT_START_Click(sender As Object, e As EventArgs) Handles BT_START.Click
Start(package)
end sub
public sub Start(package as hashtable)
Dim t As System.Threading.Thread
t = New Thread(New ThreadStart(Sub() Update.run(Me, Package)))
t.IsBackground = True
t.Start()
end sub
End Class
On run.vb file we update label: Label_status and textbox : text_box_status
Imports System.Threading
Imports System.IO
Public Class Update
public sub run(myform as form1, pakcage as hashtable)
for i to 10000
myform.Label_status.text = "Try: " + i.tostring()
update_text_box(myform.text_box_status, "Try: " + i.tostring())
Thread.Sleep(3* 1000)
end for
end sub
public sub update_text_box(MF as textbox, SYS_MSG as string)
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False
MF.AppendText(SYS_MSG & vbNewLine)
MF.Select(MF.TextLength, 0)
MF.ScrollToCaret()
files.Write(SYS_MSG & vbNewLine)
end sub
end class
i check Thread updating GUI freezes in random moments Windows Form application freeze randomly when run overnight
I am assuming that I am missing invoke or delegate methods
However, I am not clear sure why this happens. Is there anything that i missed to use thread and update Label and textbox on form?
thanks!