.NET CORE 6 MVC Threading
When you upload data into your database, it takes too much time to wait. So I want to navigate to other pages while uploading. Is it possible?
14 Replies
How long are we talking?
for long running tasks see TaskCreationOptions.LongRunning https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md
if its just milliseconds or seconds then just use like Task.Run without await
you mean leave the page that is currently submitting a file to your website?
that's what tabs are for
TaskCreationOptions.LongRunning is not recommended if that code block will be triggered too often, cause it might creates new thread for each
the solution kind of depends on more than is being stated here
if you want the "upload" to finish faster, maybe receive the file first then process it into the DB in the background
Note your need to be careful here
If you're using anything injected it will become invalid after the request ends
i don't think you can actually navigate away while the browser is making the request with the data anyway
if its like a form input then yes but once request reached to controller, other operastions can be done at background and send response immediate
if it takes time to upload database then we are lucky, otherwise have to wait form input to complete
Yes exactly. This is what I want
Sometimes, the excel file contains more than 50000rows and it takes about 10+minutes.
Can I use TaskCreationOptions.LongRunning
i suggest using hangfire
Could you explain in more detail?
cuz I have no experience.
Hangfire – Background Jobs for .NET and .NET Core
An easy way to perform fire-and-forget, delayed and recurring tasks in ASP.NET applications. No Windows Service required, backed by persistent storage.
it's a background job scheduler
thnx