-1

I'm building an application that generates excel files in asp .net core 2.2. The excel generation may takes some time depending on the user's needs. (like sometimes, it's up to 20-30s).

My question is : how can I run this generation without blocking user's navigation? Like, the user could starts the file generation, then continue his navigation on website and come back later to download the generated files. What would be the way to do so?

3 Answers 3

3

Run generation in a background task. generate name of the excel file and save the relation either in DB or in tokken (depends on your needs). when the thread will generate excel file update status in db. you can notify user or let user see the info on specific page. there are a lot more ways to do it tho...

2
  • just made my task async so now the thread is not blocked anymore. I just have to do the db part and it should be great. Thanks for the quick help !
    – j0w
    Apr 1, 2019 at 15:42
  • 2
    No, no, no. Async is not the same thing as "background". The only way you can continue before the async task finishes is if you're not awaiting it, and horrible awful bad things can happen when you do not await your async tasks. You need to actually offload it to a background process, i.e. completely outside the context of your web application. Apr 1, 2019 at 15:53
1

Not much a technical, c#-specific question, but more like a UX problem.

You could leave a button the user can click on to request the generation of said files. You run a service that receives such requests, and start processing.

When the service starts the generation, the page simply shows a message saying "Please wait, generating...".

When it finishes, change the page content to a link that allows the user to download it.

2
  • But won't this method still block the user on the generation page ?
    – j0w
    Apr 1, 2019 at 15:27
  • 1
    @j0w No. You create a request ID, return that to the client immediately, and then process the request in a side thread. The client uses the ID to request the status of that request and to fetch its results. See your other answer.
    – user47589
    Apr 1, 2019 at 15:28
0

In JS you can open a new tab, and you will be processing the excel file in this new tab.

Or, you can create the excel file on the serveur (displaying that its's currently being created), without blocking the navigation, and when your user comes back to the generating page, if a file is found, you can make it downloadable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.