How do I wait For a Web Transction to complete? [modified]
-
I'm looking for ways get my app to wait until a network stream is fully returned. Unfourtunatly NNTP uses differant stream terminators for the output of each command (if any at all), and that makes this a little awkward. My VB app calls an NNTP server via the TCPClient and reads the response. Pretty standard you'd figure. I'm having trouble with the requests that return more than one line of data, however. Basically it seems that my code is rushing to execute faster than the response comes in so the read loop is terminated because the netstream peek is empty. The response is still comming and if the app would wait a min, it would recieve the subsequent data. When i step through (or even break for a sec) the code works fine, but if I run through it without breaks, it only reads the first line. Typically I use My.application.doEvents to address these issues in forms but the read code is in a backend classlib. I've tried some simple threading algorithms (running on a sepperate thread that dosn't sleep, or pausing the main thread) but they don't seem to help either. If anyone could point me in the right direction on this I'd be most appreciative. TIA Frank hey...slang is the vernacular for the vernacular...wow -- modified at 3:06 Monday 29th May, 2006
-
I'm looking for ways get my app to wait until a network stream is fully returned. Unfourtunatly NNTP uses differant stream terminators for the output of each command (if any at all), and that makes this a little awkward. My VB app calls an NNTP server via the TCPClient and reads the response. Pretty standard you'd figure. I'm having trouble with the requests that return more than one line of data, however. Basically it seems that my code is rushing to execute faster than the response comes in so the read loop is terminated because the netstream peek is empty. The response is still comming and if the app would wait a min, it would recieve the subsequent data. When i step through (or even break for a sec) the code works fine, but if I run through it without breaks, it only reads the first line. Typically I use My.application.doEvents to address these issues in forms but the read code is in a backend classlib. I've tried some simple threading algorithms (running on a sepperate thread that dosn't sleep, or pausing the main thread) but they don't seem to help either. If anyone could point me in the right direction on this I'd be most appreciative. TIA Frank hey...slang is the vernacular for the vernacular...wow -- modified at 3:06 Monday 29th May, 2006
I'd recommend a mixture of threads and delegates. First thing to do is spawn a new thread for your stream listener "master". The only purpose of this thread is to get it off of the main forms thread so the user will not see a performance hit when it does it's work. Then, from that thread, you'll launch your additional threads. These threads should be spawned with a reference to a new instance of a class that handles all incoming events. Once that thread is running, it will send and receive all of the data relating to the newsgroup you connect it to. Now for the delegates fun :). In each thread that spawns, you should have a delegate back to the main form that will allow you to update the users gui. Now, for an explanation of why this will work. When you start the new thread with a socket it will stay open until you specifically close it or the other end closes it. If the other end closes it, it's because of a timeout issue. If a timeout issue occurs on their side then it won't matter because that is a true indication that you're not gonna get anything else from them. The delegate back to the main form will fire the event no matter what is going on. There's no need to set up a loop or anything to monitor. The rest of your code can do whatever it wants and it will fire that event whenever the new data is received. Now, you seem like the kind of person who doesn't mind research, so here's a list of what to look for: System.Threading.Thread (will launch the new thread) Delegates Sockets A mixture of those three should give you what you need. Either that, or I'm loosing my mind and I'm just rambling on :)