Hi. I want to make a call to a method within a subclassed socket and handle the return value as follows:
Dim socket As New CustomSocket
Dim Result As Boolean = socket.myMethod("some parameter")
Because the new framework socket is asynchronous I am confused how to handle the polling of myMethod waiting for a response to return because I do not want to execute any other code after the initial socket call and want to wait for the response before proceeding to handling it.
I understand I could do a Do/While loop within myMethod waiting for PageReceievd or Error event etc but this would freeze up the app and hog the processing power.
I intend to add a customTimer to the socket subclass to handle the timeout and socket.close.
Polling and loops to wait an event are old thinking. Event programming simply does not work like that. Even if you implemented a tight loop, it would freeze the entire program and most probably prevent the PageReceived event from firing.
The only way to do it without freezing everything would be to move the code to a thread. But at this point, it adds undue complexity.
Keep it simple is the way to bug free programming.
You might want to rethink your logic then… Instead of waiting for the result from the socket to continue in the current method, just move that code to an event and the socket will call the event and take care of all of the waiting, without locking up your program…
Yes, exactly. Thanks. That’s what I will have to do unfortunately. I know it’s viable it’s just I had my working system set up the other way on app launch and needed to wait for the result before deciding how to handle it and so I just now have to rethink the order of events and where to place the code etc. It’s a hassle but doable.