How to slowly add content to a web page?

B

Bruce W.1

When a user clicks on a button on my aspx page it launches a bunch of
threads which go and do things which might take a few seconds each.
Rather than waiting for all threads to complete before rendering the
response, is there a way to show the current status of each thread?

Ideally the status would be shown in a literal control or a textbox. It
would say maybe "thread started" and on completion "thread completed",
and in no particular order.

This would be analagous to a very slow rendering of the page.

How can this be implemented?

Thanks for your help.
 
G

Guest

I can't even imagine why would you need to open several
threads on a server while it processing the request? One
exception: sending email, but usually it takes no time
anyway.

The simple answer is no. But you can try to redirect user
on the same page with different text attribute of your
control using server timer. Never done this before because
there was no need :)
 
S

Scott M.

No. What the client is looking at is the RESULT of the processing that has
already taken place and completed on the server. You can think of it this
way, the web page that the client is looking at is the results from some
process that has already completed and moved on to other things.

Now, if you wanted to get into ActiveX controls or Java Applets, that would
be a different story because those are self-contained executable programs
that are launched from a web page but (once launched) can run independant of
it.
 
A

Alvin Bruney

One solution is to pass the response object as a parameter to each thread.
The thread can freely write to it whenever it starts and whenver it is done.
When you need the screen to update after thread processing you would call
the static flush method on the Response object. Off the top of my head, i'm
not sure if you will run into synchronization issues since it depends on
what part of the response object you manipulate - some methods are thread
safe others are not.

Alternatively, you can use the session object to transfer data from threads
to your main thread. Set up your main page to continuously refresh itself.
With each refresh, you check a session variable flag to determine if there
is data needed to be displayed on screen in the main page. If there is, you
retrieve data from a session variable and display it in the refresh
procedure and call flush on the response object. The session data variables
will be set by the individual threads. You will need to synchronize access.
The idea is roughly equivalent to a splash screen. That should be enough to
get you started.
 
C

Chris R. Timmons

When a user clicks on a button on my aspx page it launches a
bunch of threads which go and do things which might take a few
seconds each. Rather than waiting for all threads to complete
before rendering the response, is there a way to show the
current status of each thread?

Ideally the status would be shown in a literal control or a
textbox. It would say maybe "thread started" and on completion
"thread completed", and in no particular order.

This would be analagous to a very slow rendering of the page.

How can this be implemented?

Bruce,

http://www.fawcette.com/vsm/2002_11/magazine/features/chester/

You should be able to adapt the article to meet your needs by having
a master ("status") thread that spawns and manages the child
("worker") threads.

Hope this helps.

Chris.
 
B

Bruce W.1

Chris R. Timmons said:
Bruce,

http://www.fawcette.com/vsm/2002_11/magazine/features/chester/

You should be able to adapt the article to meet your needs by having
a master ("status") thread that spawns and manages the child
("worker") threads.

Hope this helps.

Chris.
=============================================================

If I understand this right, the results aspx page is just slowly
displaying an XML document, transformed nicely into html.

Similar behavior comes from the display of a large text file, i.e. it
displays as it loads.

So then the million dollar question is, how can this behavior be put in
to an aspx web form? Or can this behavior be put in to an aspx web
form?
 
C

Chris R. Timmons

If I understand this right, the results aspx page is just slowly
displaying an XML document, transformed nicely into html.

Similar behavior comes from the display of a large text file,
i.e. it displays as it loads.

So then the million dollar question is, how can this behavior be
put in to an aspx web form? Or can this behavior be put in to
an aspx web form?

Bruce,

The output can be in any format you want. Instead of using an
XmlDocument, you could dynamically create ASP.NET web controls, or
insert text or HTML into a literal control.

I've ported the example code to C#, and modified it to use plain text
and a literal control instead of XML for output. If you'd like, I
can zip up the code and e-mail it to you (I'll need your e-mail
address of course). Or I could post it here if anyone else is
interested.

Chris.
 
A

Aaron Lewis

Shouldn't have a problem implementing the suggestions left by others
here if you're also sure to:

- Set the page's BufferOutput property to True
- Called .Flush() after each line you want to output to the client as
the operation progresses.
- Made sure you don't have any open table tags between output. Some
browsers won't render partial tables, whether the output is flushed or not.

Also, remember that if you want to redirect or something after the
operation has completed, you'll need to do it in client script since the
HTTP headers have already been written out. Just a gotcha I've run into.
 
B

Bruce W.1

Aaron said:
Shouldn't have a problem implementing the suggestions left by others
here if you're also sure to:

- Set the page's BufferOutput property to True
- Called .Flush() after each line you want to output to the client as
the operation progresses.
- Made sure you don't have any open table tags between output. Some
browsers won't render partial tables, whether the output is flushed or not.

Also, remember that if you want to redirect or something after the
operation has completed, you'll need to do it in client script since the
HTTP headers have already been written out. Just a gotcha I've run into.

============================================================

That sounds like really good advice and I must try it sometime. But I'm
sorry to say that I have shifted gears and turned it in to a No-Touch
Deployment (NTD) winforms program, and it works great. ASP.NET is not
so great for real-time information.

Of course it only runs on .NET. That's okay for now.

I wish Microsoft would let NTD programs run in an IE browser window.
 
A

Aaron Lewis

Yeah I've done a WinForms version of my web-based application, and
working with Windows Forms is so much nicer than with web apps...
Partially because of the "neatness" factor of managing synchronization,
updating, and offline manipulation of data coming from a series of
remote web services, and using threads to do it. I'm a newbie to a lot
of parts of the .NET framework, so hitting new areas is great fun!

You know what would be REALLY cool, though? If the future version with
the Windows Forms or Avalon or whatever it's called, with the UI mark-up
called XAML (right?), could be portable between windows and web apps.
I mean, a treeview is a treeview right? If I have a Windows Forms app
with a TreeView and a ListView in it, and the output of the form is
XAML, why couldn't IIS or the framework itself see that and render
either a Windows Form or a Web Form, depending upon the context of the
client? THAT would be extremely cool. :)

By the way, about NTD in the browser, have you tried using the OBJECT
tag and referencing the DLL + class name for one of your Windows Forms
in HTML? I hear it works the way old-style OCX would..

-----
Aaron Lewis
GuildPortal.com Development
www.guildportal.com
That sounds like really good advice and I must try it sometime. But I'm
sorry to say that I have shifted gears and turned it in to a No-Touch
Deployment (NTD) winforms program, and it works great. ASP.NET is not
so great for real-time information.

Of course it only runs on .NET. That's okay for now.

I wish Microsoft would let NTD programs run in an IE browser window.

--
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top