Q:

Call an Async controller method and wait for result

I have a controller method which does a long operation and is almost coded this way
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> MyLongMethodAsync( MyViewModel model ) {
    if ( ModelState.IsValid ) {
        try {
            await _service.DoLongTaskAsync( model );
            return RedirectToAction( "LongTaskResult", new { id = model.TaskID } );
        }
        catch ( Exception e ) {
            HandleErrorViewModel he = new HandleErrorViewModel( e.Message );
            return View( "HandleError", he );
        }
    }
}

I am calling this method from jQuery in a razor view.
In the last period I have noted that the method increased the execution time to more than 5 minutes and would like to change the behaviour of the method to support a different usage.
Specifically I would like to return immediately a notification of task started to the UI and then have the UI listen for task finished event. I would like to avoid to have the UI to poll for result. Is there any other way to handle this scenario?

A:

The async-await at the server side serves it purpose which is not to waste threads that could be serving other requests instead of waiting synchronously.
This doesn't change the interaction between the client and server. For that you need another solution. I believe that SignalR is the preferred solution nowadays as it has build in support for both client (JS) and server (ASP.Net) but there are other options like XSockets for example.

