How to send an HTTP response response to a user, but after that do something else on the server?

Sometimes there is a lot to do when this action is called. Many times, more needs to be done than needs to be done to create the following HTML for the user. To make the user faster, I want to do only what I need to do to get their next view and send it, but still do more things after that. How can I do this, multithreading? Should I worry then that different threads do not step on each other? Is there any built-in functionality for this type of thing in ASP.NET MVC?

+3
source share
6 answers

As already mentioned, you can use the spawned thread to do this. I would make sure that the "criticality" of several edge cases:

  • If your background task encounters an error and fails to do what was expected to be expected by the user, do you have a mechanism to report this failure to the user?
  • Depending on how important various business-important tasks are, using a reliable / stable message queue to store “background tasks to be processed” will be protected from a scenario in which the user requests an action and those responsible with the server crashes, or is disabled, or IIS is restarted, etc., and the background thread never terminates.

Just food, although for other issues you may need to contact.

+4

, ?

!

, ?

, , ASP.NET ( ) . , , .

ASP.NET MVC?

.net ( Task Async CTP,...).

+1

, , . , , , , .Net Async, ThreadPool . , , , .

- , , , .Net, , ( -, IIS ).

- MSMQ. - . - , .

+1

, . , .NET 4.0:

public ActionResult DoSomething()
{
    Task t = new Task(()=>DoSomethingAsynchronously());
    t.Start();

    return View();
}
0

MSMQ . , ASP.NET, Asynchronous out of process . .

MSMQ ASP.NET . , ( ) , - . , IIS, threadpool - , , .

0
0

Source: https://habr.com/ru/post/1773645/


All Articles