Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,

In the program I'm making, a picturebox's image is updated 100 times per second from another thread. The image will only show if the picturebox is the only UI element on that form. So i'm guessing I should be looking into the UI thread initialization, but I'm not sure, so I won't mess with the constructor until someone tells me it's OK to do so without risking corrupting my project.

The thing is: I need more than just a picturebox on the form; i will need buttons, textboxes etc. as well. So at the moment, the only way my program can work is if the picturebox has its own form.

Please tell me how I can get this picturebox with the other UI elements!

Regards,
Ricky F
Posted
Comments
Ron Beyer 17-Jan-14 18:00pm    
You need to post code about how you are using the picturebox so we can see what you are doing to cause problems. From your description it will be difficult to figure out what is going on.
[no name] 17-Jan-14 18:05pm    
the code is just this: Picturebox1.image=bf.deserialize(client.getstream)
[where client is a tcpclient, and bf is a binaryformatter)
So it looks like it actually wasn't crossthreading, but I'm still confused about the other components interfering anyway...
Ron Beyer 17-Jan-14 18:09pm    
Is this done in a separate thread? Timer?
[no name] 17-Jan-14 18:20pm    
This is the whole code:
Dim ReceiveMessageClient As New TcpClient
Dim ReceiveMessageServer As New TcpListener(MessageReceiverPort)
Dim ReceiveMessageListening As New Thread(AddressOf receivemessageListen)
Dim GetMessage As New Thread(AddressOf ReceiveMessage)
Private Sub ReceiveMessage()
Try
While ReceiveMessageClient.Connected = True
Picturebox1.image = BF.Deserialize(ReceiveMessageClient.GetStream)
End While
Catch ex As Exception
End Try
End Sub
Private Sub ReceiveMessageListen()
While ReceiveMessageClient.Connected = False
ReceiveMessageServer.Start()
ReceiveMessageClient = ReceiveMessageServer.AcceptTcpClient
End While
GetMessage.Start()
End Sub
Ron Beyer 17-Jan-14 18:24pm    
Have you tried putting a breakpoint in the catch and see if you are getting an exception? I'm guessing its an illegal cross thread exception, probably because the UI thread has more service work when you try to set the image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900