views:

160

answers:

3

Hello,

I made a game in VB .Net that uses tcp and sends messages back and forth.

What is happening is, every so often, the message cannot be sent quickly enough, so then the TCPObj.connect() method goes into a loop, until it reaches the timeout and then spits out an error. Most of the time though, it never gets to the error, my application just freezes, and then comes back after TCPObj.connect() succeeds. How can I make the connect() method do application.doevents while it's trying to connect? Basically, I dont want it to freeze up my whole application. Since tcp.connect() is a .Net method, I can't go in and add application.doevents.

Thanks

+1  A: 

Run your TCP connectivity code on a separate thread. You can use a queue to store events to be sent from your UI and have the separate thread pick them up and process them.

Eric J.
A: 

Put the connecting to the TCP in another thread. You can use the Async callback to get back to the main thread. If it errors out on the other thread because of timeouts you can deal with it there or on the main thread.

David Basarab
A: 

you should use a backgroundworker

Fredou