I'm trying to make an async action in my async controller. All I need to do is when I press the button in the view it give me an alert indicating that the work has been sent for getting done. and when the job get's done I can do something (For example returning a json or redirect to another view). Here is my code:
Server side:
public void DoWork()
{
var a = MakeADelay();
}
public async Task<ActionResult> MakeADelay()
{
await Task.Delay(5000);
return RedirectToAction("UploadComplete");
}
public ActionResult UploadComplete()
{
return View();
}
and this is my client side code :
$("#btnAsync").click(function () {
$.ajax({
url: '/Upload/DoWork',
type: "post",
success: function () {
alert("Work in Progress!!");
}
});
});
When this code runs all seems to execute as expected but when the server side code reaches the statement return RedirectToAction("UploadComplete");
it does nothing ! I think it runs in another thread or something.
what is the problem ?
Second question is what does aync action actually mean ? I never want my action to await for statements to get complete. I always want my actions to sent jobs to execution queue and return back to client, and when the jobs has completed I can notify the client in some way. How can I notify the client anyway ? with SignalR or something ?