Multi-threaded library calls in ASP.NET page request.

Posted by ProfK on Stack Overflow See other posts from Stack Overflow or by ProfK
Published on 2010-06-04T22:40:14Z Indexed on 2010/06/05 9:02 UTC
Read the original article Hit count: 268

Filed under:
|
|

I have an ASP.NET app, very basic, but right now too much code to post if we're lucky and I don't have to.

We have a class called ReportGenerator. On a button click, method GenerateReports is called. It makes an async call to InternalGenerateReports using ThreadPool.QueueUserWorkItem and returns, ending the ASP.NET response. It doesn't provide any completion callback or anything.

InternalGenerateReports creates and maintains five threads in the threadpool, one report per thread, also using QueueUserWorkItem, by 'creating' five threads, also with and waiting until calls on all of them complete, in a loop. Each thread uses an ASP.NET ReportViewer control to render a report to HTML. That is, for 200 reports, InternalGenerateReports should create 5 threads 40 times. As threads complete, report data is queued, and when all five have completed, report data is flushed to disk.

My biggest problems are that after running for just one report, the aspnet process is 'hung', and also that at around 200 reports, the app just hangs.

I just simplified this code to run in a single thread, and this works fine. Before we get into details like my code, is there anything obvious in the above scendario that might be wrong?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET