我的控制器中有这样的方法:
[HttpPost]
public async Task<string> GetMenu(int? Current) {
await Task.Run(() => System.Threading.Thread.Sleep(60000));
return "";
}
我从下面这样的JQuery Ajax请求开始:
$.ajax({
type: "POST",
url: '@Url.Action("GetMenu","Products")',
data: "{}",
async: true,
success: function (data) {
$('#menu-container').html(data);
},
});
并且浏览器在处理GetMenu动作的时间内冻结。如何在后台以非阻塞的方式工作?
发布于 2015-05-22 10:23:15
我想你需要这样的东西
html
<pre id="testpre">
not end
</pre>
JS
$.post("/Home/ProtocolAjaxHandler", { }, function (data) {
$("#testpre").html("END");
});
控制器
[HttpPost]
public ActionResult ProtocolAjaxHandler(object _param)
{
System.Threading.Thread.Sleep(15000);
return Json(null);
}
发布于 2015-05-22 10:28:12
如何在后台以非阻塞的方式工作?
正如我在我的博客async
doesn't change the HTTP protocol上解释的那样。根据您实际尝试的目的,您可以尝试使用SignalR,也可以使用具有可靠队列和独立后台进程as I allude to in another post的分布式体系结构。
https://stackoverflow.com/questions/30390868
复制