Question How to return a response to the API request to the client and continue executing the code on the server?

And1985

New member
Joined
Jun 4, 2022
Messages
3
Programming Experience
1-3
Good day!
I have a question, on the server through API the request from the client comes.
On the ASP NET MVC server, it is processed and returns a response.
But the processing can be very long. There are at first a lot of checks, calls to a DB. Then the main transaction with several records to the database and at the end a few more actions.

There is a desire to speed up this, return the response to the client immediately after the transaction, and then complete the tail section using a separate method.
Is there a solution for such a task?
That is, after the transaction of the main method is completed, call the additional method separately, and the main method is completed without waiting for the additional one.
 
After the transaction, I need to return the status to the client (if successful, then return the ID of the new element in the table).
All further operations (aka tail section) will already be performed without notifying the client.
 
Start another thread to for the tail section, or queue the tail section into the thread pool. The latter can be done by using Task.Start().
 
Skydiver, thank you!
I'm already looking this way (queue the tail section into the thread pool).
Looks like this is what I need!
 
Back
Top Bottom