User request some page at my website.
What i want to do? Send to user a fast answer and start background task which take a long time. It looks like:
public ActionResult index()
{
var task = new Task(Stuff);
//start task async
task.start();
return View();
}
public void Stuff()
{
//long time operation
}
How can i do it?
A long running task is a task that requires more than 30 seconds to complete and involves a large amount of data.
Scheduling deferred work through WorkManager is the best way to handle tasks that don't need to run immediately but which ought to remain scheduled when the app closes or the device restarts.
A background task is a task performed by a system during the time when its primary application is idle.
You can pass the Task StartNew() method a parameter that indicates the task you're starting is "long running", which provides a hint to the Task Scheduler to start the task on a new thread.
var task = Task.Factory.StartNew(Stuff, TaskCreationOptions.LongRunning);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With