Last post Jun 20, 2013 06:22 PM by DMW
Jun 13, 2013 12:20 PM|dbrownsd|LINK
I have a VB .net web application that has some extensive reporting capabilities built in. Some of these reports can take upwards of 10 minutes to aggragate all the necessary data from the database and generate the final report. I would like to spin the report
generation off into a separate thread that will ulitmately result in the report being emailed to the user.
I have started to set this up using the BackgroundWorker process, but my issue is that the UI hangs while the background worker is running and is not released to the user to continue working.
How can I spin this process off while releasing the UI to the user to continue working in the application?
Jun 13, 2013 02:35 PM|adamturner34|LINK
If you're not going to monitor the progress, simply use System.Threading.Thread.Start()
Jun 13, 2013 04:45 PM|dbrownsd|LINK
That works to release the UI, however I have another issue cropping up.
Sorry to sound like I'm unsure of what I'm doing but I've only been programming for a year now....
I'm running into some issues in the report generation where httpcontext.current needs to be accessed. If I pass it in, by the time I need it, the users actual context has changed, and what I've passed is out of sync.
Is there any safe way for me to access the users current context from the separate thread?
Also the question has been raised if it is even possible to transmit the file (download prompt) instead of emailing it? Any thoughts on that?
I thank you for all your help.
Jun 13, 2013 10:23 PM|adamturner34|LINK
Not unless you have a time machine.
A report is a report. Larger reports take time to generate. Trying to synch a loading report with changing data is not impossible but impracticle. The only way to get a clean read is via explicit transactions but that will lock the database until the report
Jun 14, 2013 10:31 AM|dbrownsd|LINK
I guess I didn't explain myself very well.... agan, noobie problems.
I'm not trying to break into the current context to sync the loading report with the changing data. I don't need up to the second data for these reports, this is basically from static finalized data.
The reason I'm trying to break back into the current context (please help me use the correct terminology if you can)... is that I have been asked to set this up using a transmit functionality if I can as a proof of concept before the other dev spends time
writing the email process for this. I'm getting the report generated just fine, but when I go to transmit the file to the user the function calls current.response.clearheaders... I get an error that the current headers could not be cleared once they have been
sent. Basically I need to figure out how to pass the completed byte() that contains the report back to the UI thread so that I can access the true current context that allows me to initiate the file transmit process.
Jun 20, 2013 06:22 PM|DMW|LINK
You have fundamental architectural issues with your approach.
Firstly, you should be moving the report generation out of the web application and into a separate process. What should happen is that the user should go through the UI to create their report, and when they submit the request, you should cache this information
into a database. This ensures that if there is a worker process restart, the report will not be lost.
Then, in your separate process (i.e. different program), you can harvest the report database and generate the reports. This can take considerable time, so you will probably want to use a controlled number of threads to do this - otherwise, you might end
up thrashing the cores / OS scheduler to the point that no real work gets done - just thread scheduling.