Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To thread or not to thread ? 1

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I've got a situation whereby I'm processing a number of database records behind an ASP.NET web page (I'm using C# code).
Let's say I'm processing 5000 records.
Rather than have the user simply click a button and then report the work is done on completion (after 5000 record processing) I'd favour the idea of keeping the user up to date with how many records have been processed so far, via means of a progressbar or a simple counter of sorts.
How would I be able to do this ?
Would I need to make use of a thread'ing concept or is there some other (better) way of doing this ?
I need to know the number of records I'm into the process and visually represent this to the user.
Thanks in advance.
Steve
 
Threading is definitely the way to go, but in the web world, you face UI obstacles that are so much simpler to overcome in the winforms world.

Where in the winforms world, you would construct a simple callback structure whereby your worker thread would send alerts as to its progress, which is easily updated to a progress bar, you really can't do that with the web.

What I do is setup a page with two panels:

(1) pnlWorking
- and -
(2) pnlFinished

pnlWorking holds information about progress... or even just a simple "Please wait while I process your request" message. pnlFinished holds whatever I want to show them when I'm done.

Page starts off by spinning off a worker thread to do the heavy lifting. At the time I send him to do his work, I also send him the location of a file where he can update me as to his progress.

Then, the page sets the following script:

<script language=javascript>
setTimeout(5000, 'DoPostBack()');
function DoPostBack{}
{
document.forms[0].submit();
}
</script>

So that the page sits for 5 seconds and then posts back. Upon Page_Load, I check that file for an update. If it's not done, then I update the user (maybe there's a % done in the file in your case) to the pnlWorking, and reset the postback script.

Rinse and Repeat.

Once the file has the finished flag, then you can show the pnlFinished, and you've now created a multi-threaded web app.

:)
paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Nicely done paul. Often wondered about this but never took the time to look at it.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
I've just been reading about the very same topic (although I haven't had time to try it out yet). It works on the same principle of updating a page every few seconds to inform the user of progress.

Have a look at:

Part 1: Part 2:

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top