C
C#5mo ago
John

.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
jcotton42
jcotton425mo ago
How long are we talking?
atakancracker
atakancracker5mo ago
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
Jimmacle
Jimmacle5mo ago
you mean leave the page that is currently submitting a file to your website? that's what tabs are for when
atakancracker
atakancracker5mo ago
TaskCreationOptions.LongRunning is not recommended if that code block will be triggered too often, cause it might creates new thread for each
Jimmacle
Jimmacle5mo ago
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
jcotton42
jcotton425mo ago
Note your need to be careful here If you're using anything injected it will become invalid after the request ends
Jimmacle
Jimmacle5mo ago
i don't think you can actually navigate away while the browser is making the request with the data anyway
atakancracker
atakancracker5mo ago
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
John
John5mo ago
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
Jimmacle
Jimmacle5mo ago
i suggest using hangfire
John
John5mo ago
Could you explain in more detail? cuz I have no experience.
Jimmacle
Jimmacle5mo ago
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.
Jimmacle
Jimmacle5mo ago
it's a background job scheduler
John
John5mo ago
thnx
Want results from more Discord servers?
Add your server
More Posts