Refresh UI Form from Workflow

I am new to VB.NET multithreading and have encountered a problem due to which I want to add text to the form text field from a service flow that is running in the background.

The application I'm developing is a client / server listener, I was able to get the client and server PCs to talk to each other (confirmed through MsgBox), however now I am trying to get a service flow on the server to add text to the text field, nothing is valid.

I have a form called testDebug that calls a class (RemoteSupport), this class does the whole handshake and updates the text field with the connection data.

Can someone determine where I'm going and point me in the right direction?

The following is the code that I have: The form has a text field called txtOutput, which is from the 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 UpdateUIDelegate(AddressOf HandleClientComm), New Object() {outMessage})    '
    Else
       testDebug.txtOutput.AppendText(outMessage)
    End If

    'RaiseEvent MessageReceived(outMessage) // a previous attempt to use custom events
 End If

I'm not sure if the invoke method is the perfect solution or if custom events, I spent some time trying to get custom events to work, but they didn't work either.

 // In the RemoteSupport class
 Public Delegate Sub MessageReceivedHandler(ByVal message As String)
 Public Shared Event MessageReceived As MessageReceivedHandler

// Located throughout the RemoteSupport class where debug information is required.
RaiseEvent MessageReceived(outMessage)

// Located in the code-behind of the form
Private Sub Message_Received(ByVal message As String)
testDebugOutput(message) // this is a function I have created 
                         // to append the text to the text box
End Sub

The code provided has been shortened, so if there is anything else you want to see or any questions, please let me know.

Thank you for your help.

EDIT: I uploaded two VB files (form and class) to my site, I would appreciate it if someone could take a look at it to help me identify a problem with updating the user interface.

I tried several other things, but nothing seems to update the user interface after starting the workflow.

: mulholland.it/testDebug.vb.txt : mulholland.it/remoteSupport.vb.txt

.

Matt

+3
2

testDebug...

If testDebug.InvokeRequired Then

VB.NET. If. , False, , ?

InvokeRequired - . testDebug - , testDebug. , VB.NET, VB.NET . , VB6. , . , , . , , Show() . doornail, .

, . , :

+6

Delegate, , , , UpdateUIDelegate -

, (, testdebug, remotesupport

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
0

Source: https://habr.com/ru/post/1770573/


All Articles