Update UI form from worker thread

后端 未结 2 631
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 23:38

I am new to multi-threading in VB.NET and have come across a problem whereby I am wanting to append text to a text box on a form from a service thread running in the backgro

2条回答
  •  一整个雨季
    2020-12-12 00:20

    The Delegate method is likely the way you want to go, but I don't see the declaration of the UpdateUIDelegate anywhere

    I believe your code should look something like this (assuming you have a reference to the testdebug form local to your remotesupport class

    Dim outMessage As String = (encoder.GetString(message, 0, bytesRead))
    MsgBox(outMessage, MsgBoxStyle.Information, "MEssage Received")
    If outMessage IsNot Nothing Then
        If testDebug.InvokeRequired Then
            ' have the UI thread call this method for us
            testDebug.Invoke(New MessageReceivedHandler(AddressOf Testdebug.Message_Received), New Object() {outMessage})   
        Else
            testDebug.txtOutput.AppendText(outMessage)
        End If
    end if
    

提交回复
热议问题