Background tasks in ASP.NET

I am in a situation where I have to run multiple async tasks (like sending emails, processing files etc.) after a user makes a request to the server. They are not heavy-weight tasks by any means but would still make the response time slow if I don't run them in the background. Currently, I have them set up as following: https://1921681254.mx/

public async Task<IActionResult> OnPostAsync() {

AsyncTask1();
AsyncTask2();
AsyncTask3();

return Page();https://100001.onl/

}
The response is returned quickly this way and the tasks are processed but I'm not sure if this is the correct way of doing it. I would appreciate if anyone could critique my code and provide a better (and preferably equally simple) solution.

Thanks!
Last edited on
This is not c++ but c#.

For this requirement async seems pretty much okay. As long as you don't expect a particular order of execution.

Async means that there is no parallel processing.

One async task is processed until it waits for some input. While it waits other async tasks are processed.

So it's fine as long the task contains waiting and not too much processing and the order of processing doesn't matter.
Topic archived. No new replies allowed.