ASP.NET Threading Questions

G

Guest

Hello!



I have a C# ASPX page that displays a large amount of information. The
software loops through 500 lines of code (and some of the 500 lines are
looped multiple times, in a loop). Naturally, it takes approximately 7
seconds for the Page_Load event to fire (where I have all of my code).



I thought that going down the threading road would be a good idea – it cut
my execution time in half. However, sometimes the thread finishes after the
page has displayed, a bad deal. How do you generate large amounts of data,
and then display it? Are there any threading tricks?



Thanks,



JMax
 
N

Nicholas Paldino [.NET/C# MVP]

JMax,

Threading in an ASP.NET application when you only have one task to
complete (your loop) is a bad idea. The reason is that you are starting up
another thread while your processing thread (the one that returns the
response to the browser) is basically sitting around waiting (it should be
waiting, that is).

Unless you can break out the task in the loop to other threads (which
you have to wait for), there is no point in doing what you are doing. You
will have to consider what the page is doing, and see if you can offload the
processing to another process.

Hope this helps.
 
M

Michael Nemtsev

Hello JMax,

Are you really need to show all that data on one page? Maybe to apply asyc
calls to get dependent data? To show minumum info for user
and all dependent data (for example data in dropdown boxed) get async?

J> I have a C# ASPX page that displays a large amount of information.
J> The software loops through 500 lines of code (and some of the 500
J> lines are looped multiple times, in a loop). Naturally, it takes
J> approximately 7 seconds for the Page_Load event to fire (where I have
J> all of my code).
J>
J> I thought that going down the threading road would be a good idea -
J> it cut my execution time in half. However, sometimes the thread
J> finishes after the page has displayed, a bad deal. How do you
J> generate large amounts of data, and then display it? Are there any
J> threading tricks?
J>
J> Thanks,
J>
J> JMax
J>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
I

Ignacio Machin \( .NET/ C# MVP \)

HI,
I thought that going down the threading road would be a good idea - it cut
my execution time in half. However, sometimes the thread finishes after
the
page has displayed, a bad deal. How do you generate large amounts of data,
and then display it? Are there any threading tricks?

It's not a good idea, it does the opposite as a matter of fact.
You have two options:
1- try to send chuck of the page back to the client, so the client sees part
of the page whiel you are generating the rest.
2- try to show less data in your page and use pagination if possible

You do not especify details about your problem so we cannot give you better
answer, you could also use caching or maybe improve the data generation
algorithm.
 

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

Top