Hi Guys,

I've just started learning the multithreading in vb.net; Needless to say I'm facing issues.
Please check the code written below as its not giving any output, it just hangs.

Public Class Form1

    Private Delegate Sub _invokeUIControlDelegate(ByVal errMsg As String)
    Dim Thread1 As New System.Threading.Thread(AddressOf doSome1)
    Dim Thread2 As New System.Threading.Thread(AddressOf doSome2)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Thread1.IsBackground = True
        Thread1.Start()
        Thread2.Start()
        Thread1.Join()      ' Wait for the thread to finish.
        Thread2.Join()
        MsgBox("Thread is done")
    End Sub

    Private Sub DisplayError(ByVal errMsg As String)
        txtData.Text = errMsg
    End Sub

    Private Sub DisplayErrorOnUI(ByVal errMsg As String)

        If (Me.InvokeRequired) Then
            Dim invokeDelegate As _invokeUIControlDelegate = New _invokeUIControlDelegate(AddressOf DisplayError)
            Me.Invoke(invokeDelegate, errMsg)
        Else
            DisplayError(errMsg)
        End If
    End Sub

    Private Sub doSome1()
        For i As Integer = 0 To 11
            DisplayErrorOnUI("By 1")
        Next
    End Sub

    Private Sub doSome2()
        For i As Integer = 0 To 11
            DisplayErrorOnUI("By 2")
        Next
    End Sub

End Class

Please tell me whats wrong here??

Solved the problem myself...:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.