Beckett

Hi,

I have an application that can take images from a number of different client svia a TCP connection. The application structure is a s follows:

I have a form which has a picturebox. It has a class that launches a TCPlistner. The TCPListner waits for a connection; on receiving one it uses a threadpool to handle the receipt of an image from the TCP connection. An event is raised and a NewImage method runs on the main form. The HandleNewImage method uses a delegate to update the picturebox. The problem is that the application appears to hang on the Invoke statement inside the HandleNewImage call. I have included some code from the main form below.

Delegate Sub UpdateImageHandler(ByVal bmp As Bitmap)

Public Sub UpdateImage(ByVal bmp As Bitmap)

pctMain.Image = bmp

End Sub

Private Sub HandleNewImage(ByVal sender As Object, ByVal e As ImageEventArgs)

Dim bmp As Bitmap = e.Bitmap

If Me.InvokeRequired Then

Try

Me.Invoke(New UpdateImageOnlyHandler(AddressOf UpdateImage), bmp)

Catch ex As Exception

MsgBox(ex.Message)

End Try

Return

End If

UpdateImage(bmp)

End Sub

Any suggestions as to what may be happening



Re: Visual Basic Language Problems updating UI with invoke

pyeung

Try Me.BeginInvoke rather than Me.Invoke.






Re: Visual Basic Language Problems updating UI with invoke

Beckett

Hi pyeung,

I tried that and get the same behaviour





Re: Visual Basic Language Problems updating UI with invoke

TaDa

Expound on "appears to hang". Does it just stop on that line in the debugger or what





Re: Visual Basic Language Problems updating UI with invoke

Beckett

The method that should be invoked is never called and the application becomes unresponsive. I can kill the application with the debugger, but the debugger is no longer stepping through the code. The problem appears to be with the registering of handler for the method that is going to be invoked. I have changed the threading architecture of the application and can now invoke. I will post more details once I understand it all a little better. Thank you for your reply.





Re: Visual Basic Language Problems updating UI with invoke

nobugz

You've got an oops at the bottom of HandleNewImage(). You are still calling UpdateImage(), even if InvokeRequired is True. Put it in the Else part of the If statement.





Re: Visual Basic Language Problems updating UI with invoke

Beckett

Thanks for that