Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long Process in ASP.NET Web Forms - Browser Timeout

I realise this question has been asked in different variations but with newer features to .net (e.g. async await) I wonder what solution is the best.

I have a C# .Net Web Forms app that has a long running task: The task handles a user request where they upload a csv data file, serialises into object, and imports to a database. The task can take a few minutes and the browser regularly times out - this causes usability issues.

I have seen many solutions whereas the user will upload the data and then the task is carried out in the background. The page will then call the server intermittently to request the status of the task, thus keeping the user informed of the progress.

I would like to know how this is achieved? The options I see on the table:

  • Windows Service
  • Web Service - how is this hosted: IIS or a windows service?
  • Async, Await - is this a possibility?
like image 880
David Avatar asked Apr 24 '26 14:04

David


1 Answers

I think you could take two different approaches.

The first would be a pull approach, you would be keeping the state of the process per user in the server, perhaps in session, and having the process update that state, then the client can pull the actual state via ajax regularly. The ajax call is made from the client's browser, and the function can be put in the same web page that the client is viewing, there's no need to separate it if it's going to be used only from there.

The second could be a push approach, which is a bit more complex but gives you other possibilities. You would need to use a library like signalr https://www.asp.net/signalr, that allows you to communicate from the server to the client's browser, call JS functions, and push the updated state to the client's form. That could create a more functional two-way communication and a better user experience in exchange of a bit more complexity.

like image 123
Leonardo Allievi Avatar answered Apr 27 '26 04:04

Leonardo Allievi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!