<p>In my web application there is a process that queries data from all over the web, filters it, and saves it to the database. As you can imagine this process takes some time. My current solution is to increase the page timeout and give an AJAX progress bar to the user while it loads. This is a problem for two reasons - 1) it still takes to long and the user must wait 2) it sometimes still times out.</p>

<p>I've dabbled in threading the process and have read I should async post it to a web service ("Fire and forget").</p>

<p>Some references I've read:<br>
- <a href="http://msdn.microsoft.com/en-us/library/ms978607.aspx#diforwc-ap02_plag_howtomultithread" rel="nofollow noreferrer">MSDN</a><br>
- <a href="http://aspalliance.com/329" rel="nofollow noreferrer">Fire and Forget</a></p>

<p>So my question is - what is the best method?</p>

<p>UPDATE: After the user inputs their data I would like to redirect them to the results page that incrementally updates as the process is running in the background.</p>

[{'answer_id': 73082, 'author': 'kemiller2002', 'author_id': 1942, 'author_profile': 'https://Stackoverflow.com/users/1942', 'pm_score': 1, 'selected': False, 'text': "<p>I ran into this exact problem at my last job.  The best way I found was to fire off an asychronous process, and notify the user when it's done (email or something else).  Making them wait that long is going to be problematic because of timeouts and wasted productivity for them.  Having them wait for a progress bar can give them false sense of security that they can cancel the process when they close the browser which may not be the case depending on how you set up the system.  </p>\n"}, {'answer_id': 73148, 'author': 'ahin4114', 'author_id': 11579, 'author_profile': 'https://Stackoverflow.com/users/11579', 'pm_score': 0, 'selected': False, 'text': "<ol>\n<li>How are you querying the remote data?</li>\n<li>How often does it change?</li>\n<li>Are the results something that could be cached for a period of time?</li>\n<li>How long a period of time are we actually talking about here?</li>\n</ol>\n\n<p>The 'best method' is likely to depend in some way on the answers to these questions...</p>\n"}, {'answer_id': 73170, 'author': 'wile.e.coyote', 'author_id': 12542, 'author_profile': 'https://Stackoverflow.com/users/12542', 'pm_score': 2, 'selected': False, 'text': '<p>We had a similar issue and solved it by starting the work via an asychronous web service call (which meant that the user did not have to wait for the work to finish).  The web service then started a SQL Job which performed the work and periodically updated a table with the status of the work.  We provided a UI which allowed the user to query the table.</p>\n'}, {'answer_id': 73171, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>You can create another thread and store a reference to the thread in the session or application state, depending on wether the thread can run only once per website, or once per user session.<br />\nYou can then redirect the user to a page where he can monitor the threads progress. You can set the page to refresh automatically, or display a refresh button to the user.<br />\nUpon completion of the thread, you can send an email to the user.</p>\n'}, {'answer_id': 73177, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': '<p>My solution to this, has been an out of band service that does these and caches them in db.</p>\n\n<p>When the person asks for something the first time, they get a bit of a wait, and then it shows up but if they refresh, its immediate, and then, because its int he db, its now part of the hourly update for the next 24 hours from the last request.</p>\n'}, {'answer_id': 73428, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 4, 'selected': True, 'text': '<p>To avoid excessive architecture astronomy, I often <a href="http://encosia.com/2007/10/03/easy-incremental-status-updates-for-long-requests/" rel="nofollow noreferrer">use a hidden iframe to call the long running process and stream back progress information</a>.  Coupled with something like <a href="http://www.bram.us/demo/projects/jsprogressbarhandler/" rel="nofollow noreferrer">jsProgressBarHandler</a>, you can pretty easily create great out-of-band progress indication for longer tasks where a generic progress animation doesn\'t cut it.</p>\n\n<p>In your specific situation, you may want to use one LongRunningProcess.aspx call per task, to avoid those page timeouts.  </p>\n\n<p>For example, call LongRunningProcess.aspx?taskID=1 to kick it off and then at the end of that task, emit a </p>\n\n<pre><code>document.location = "LongRunningProcess.aspx?taskID=2".  \n</code></pre>\n\n<p>Ad nauseum.</p>\n'}, {'answer_id': 73485, 'author': 'tbone', 'author_id': 8678, 'author_profile': 'https://Stackoverflow.com/users/8678', 'pm_score': 0, 'selected': False, 'text': '<p>Add the job, with its relevant parameters, to a job queue table.  Then, write a windows service that will pick up these jobs and process them, save the results to an appropriate location, and email the requester with a link to the results.  It is also a nice touch to give some sort of a UI so the user can check the status of their job(s).</p>\n\n<p>This way is much better than launching a seperate thread or increasing the timeout, especially if your application is larger and needs to scale, as you can simply add multiple servers to process jobs if necessary.</p>\n'}]
['https://Stackoverflow.com/questions/73039', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12442/']