Question Loop conundrum

danfloun

Member
Joined
Apr 5, 2010
Messages
23
Programming Experience
Beginner
Okay so I've got my app retrieving and validating an ip from a website.
I now want to run a test when the app starts which loops through an array of urls and checks that ip retrieval works.

I would like to do this using my present asynchronous requests.
The problem is, I have an urlList array, but the asynchronous requests require a callback to determine whether the request was successful.

So this means two subs, so I can't use loop to iterate through the routine and then start back at the calling sub using the next url.

How can I get around this?
Would I have to use synchronous requests instead to keep it all in the same sub, but create a separate thread to stop my UI from freezing?

I should say, I don't want the array of urls to be checked in in multiple threads at the same time, I want to iterate through one url at a time so I can time the requests.

Cheers
Danny
 
Never mind, I should have thought about this more.

What I will do is change the callback sub to a function, then use the OpenReadCompleted event to trigger the next loop in the calling sub.

I think...
 
I'm stilling having problems and I could do with some pointers if someone can assist.

As above, I have code that parses an IP address from sites such as whatismyip.org. I have around 12 sites in an array.

I wish to loop through the sites, one at a time not synchronously, and time how long it takes from the start of the actual request to the closing of the stream.

For the majority of sites this will be milliseconds, but nevertheless I want to use it to find dead urls and slow links and then re-arrange the array from fastest to slowest.

The latter part I can do, I can even loop through and get the requests.
However, if I use Asynchronous requests then all the requests are done at the same time which screws up the timing. So I need some method of returning a parameter from the callback sub which processes the result, which then triggers the next loop, I don't even know if that's possible.

I can successfully use synchronous requests and time their response, but the UI locks up while this runs and I get no feedback to the ui after each request.
I wish to get a time and ip address pushed to the UI after each request is made.

So I assume this would require initiating the webrequest in a worker thread and doing something to update the ui after each request?

I really don't know which route to go down.
Any advice would be great.

Danny
 
Back
Top