looping and displaying progress with every iteration

B

Bruce Whitehouse

This should be an easy one, but I'm not sure the best way to do it.

I've got a form, and when I click a button it starts looping through an
array. With each iteration of the array I want it to change the status of a
label.

I realise that it must complete the execution of the code-behind page before
it can update the labels, so how do I do it?

TIA, Bruce
 
B

Bruce Whitehouse

Thanks Alvin

What I was wanting to do was loop through some code in my VB (code behind
page). The loop is actually going through 15 or so web services (which take
up to 2 minutes each), so on each iteration of the loop (for each
webservice) I wanted to let the user know what the status was of each web
service call.

I'm about to re-write the page using an array and a datagrid. I'll be
letting the page complete, checking for what is to happen next, execute the
method, update label, let page reload, etc, etc.

So I can't have the page reload every 2 seconds. Firstly because the web
service method that I'm calling returns a true value, and I have to wait for
it to be returned.

Bruce
 
A

Alvin Bruney

Understood, but you are missing something here. You will need a refresh to
update the client with whatever happens on the server. If you don't refresh
there is no possible way of notifying the client that you are making
progress because your main process cannot update the client while it is
polling the webservices.

On each refresh you will need to read a variable which tells you the
percentage completion, typically stored in session or viewstate. This
variable is set by your procedure which iterates over the webservices. So
for example, as you pass thru each webservice and you retrieve a request,
your percentage complete becomes x/15 * 100. You set that viewstate
variable. At this point, you force an immediate screen refresh. But your
code moves on in the iteration. The refresh updates the client with the
percentage completed. This algorithm persists until all the iteration is
done.

Alternatively, if the output of each webservice is not dependent on the next
webservice call, I suggest you thread the application. For example, if you
spawned five threads, each thread queries 3 webservices all done at the same
time, you can potentially improve performance 5 fold because each thread
will be executing at roughly the same time (more or less).

Put another way, if you send your son to town to get the morning paper, you
cannot have the paper until he comes back. You will be left waiting for as
long as he takes to get the paper. On the other hand if you send him with
his sister (threading) and periodically, his sister leaves him in town to
come back to let you know what is happening, you receive valuable updates
and your wait time is 'easier'.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top