View Single Post
Old 09-19-2013, 08:20 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500

If you have a situation like this:
Sub A()
End Sub

Sub B()
End Sub
You're going to stack overflow no matter what. Every recursive routine needs an exit condition. If you don't write one, the only difference between that an an infinite loop is eventually recursion stack overflows.

If you want to continue listening for data with some exit condition that can't be governed by these two methods, use asynchronous calls. You can look up the details in the documentation, but the pattern looks like this:
Sub WaitForData()
    ' blah blah setup code
    serverStream.ReadAsync([blah blah], AddressOf DataArrived)
End Sub

Sub DataArrived(blah blah)
    ' end the asynchronous operation, process results...
End Sub
My guess is NetworkStream's using the IAsyncResult pattern, but you can find out all about that in the documentation. Or ask questions about it!

You'd actually get better results if, instead of asking "How do I make this code work?", you revised it to "What's the right way to accomplish <goal>?"
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote