C# asp.net asynchronous function call after file is uploaded
I'm facing the following issue: I have a C# asp.net file upload form with a submit button. After the form is submitted the file is uploaded and post-processing is started. The point is that the post-processing can take up to several minutes.
I would like to create some kind of asynchronous call of the post-processing function with showing information to the user.
So, the steps should be:
- file form is submitted by user and upload is started
- after the file is uploaded some information is shown to the user (e.g. "Processing..." or some loading-bar animation, etc.)
- Meanwhile, the post-processing function is automatically started running in a background
- After the post-processing function is finished the user is automatically redirected to another page
When i was search开发者_Python百科ing the Internet I've found several examples but mostly only about asynchrounous call of functions, asynchrounous file upload (PageAsync method, etc.).
Any idea or techniques I should use or some tutorial? Thanks in advance
That all depends on how fancy you want to get;
- Meta-refresh that reloads the page until the background operation is finished
- Some kind of ajax call that checks some resource for when the processing is done
- HTML5 websockets. if supported, which it probably isn't.
Personally I would use the number 2. and use jQuery to poll the upload page every 500ms or something.
You can use AJAX
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
http://vinayakshrestha.wordpress.com/2007/03/13/uploading-files-using-aspnet-ajax-extensions/
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=upload+using+Ajax&qscrl=1#sclient=psy&hl=en&qscrl=1&source=hp&q=upload+using+Ajax+in+asp.net&aq=f&aqi=&aql=&oq=&pbx=1&fp=db9c4fafd449a821
The jquery/flash control uploadify will allow you to do this easily. They also provide a method for asynchronously calling a method on the event that the file upload completes as described in this comprehensive documentation.
I have looked at a lot of places for a good example, and this is the one I like the best so far.
It does not handle the uploading, but it does a fine job at showing real progress to the user and it is not difficult to implement http://inov8.wordpress.com/2010/08/29/c-asp-net-creating-an-asynchronous-threaded-worker-process-manager-and-updatepanel-progress-monitor-control/
精彩评论