I'm trying to update a label which is running in the UI thread from a Module(On a diff thread). When user hit run button a new thread is created and procedure DVD is run in it. My problem is when the program is run and the invoke required is tested it always returns false, which then doesn't update my label and also I don't get error even though the procedure is on a diff. thread. Tried a lot of stuff but nothing seems to works. What am I doing wrong? Please help..... Thanks.
Imports System.Threading
Public Class Form1
Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Dim t0 As Thread
MyPath1 = TextBox31.Text
Label114.Text = "Working on it. Please Wait ..."
t0 = New System.Threading.Thread(AddressOf DVD)
t0.IsBackground = True
t0.Start()
End sub
End Class
-----------------
Public Module MdlDVD
Sub DVD()
Do Some Work ............
If form1.Label114.InvokeRequired = True Then
Form1.Label114.Invoke(Sub() form1.label114.Text = "Processing Complete ...")
Else
Form1.Label114.Text = "Processing Complete ..."
End If
End Sub
End Module
Edit:
Imports System.Threading
Public Class Form1
Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
Dim t0 As Thread
MyPath1 = TextBox31.Text
Label114.Text = "Working on it. Please Wait ..."
t0 = New System.Threading.Thread(AddressOf DVD)
t0.IsBackground = True
t0.Start()
End sub
Public Delegate Sub SetControlPropertyThreadSafeDelegate(Control_Name As Control, propertyName As String, propertyValue As Object)
Public Sub SetControlPropertyThreadSafe(Control_Name As Control, propertyName As String, propertyValue As Object)
If Me.Label114.InvokeRequired Then
Me.Label114.Invoke(New SetControlPropertyThreadSafeDelegate(AddressOf SetControlPropertyThreadSafe), Control_Name, propertyName, propertyValue)
End If
End Sub
End Class
-----------------
Public Module
Sub DVD()
Do Some Work ............
Thread.Sleep(1000)
form1.SetControlPropertyThreadSafe(GoProTools.Label114, "Text", "Processing Complete ...")
End Sub
End Module
But still the same problem exist. RequiredInvoke is still coming out to false. also please suggest wether or not i have implemented it correctly.. thanks ....