【发布时间】:2012-08-10 19:36:43
【问题描述】:
是否可以在 MVC3 Action 方法中异步/并行调用方法?
public ActionResult CreateUser(string name,string password)
{
int newUserId= myRepositary.CreateUser(name,password)
if(newUserID>0)
{
//i want to execute this asycn /parallel ?
UpdateUserIDINRelatedTables();
}
return RedirectToAction("AccountCreated");
}
public void UpdateUserIDINRelatedTables()
{
//I will update the userId in few another tables.
}
UpdateUserIDINRelatedTables 执行一些后端工作以将新的 USERID 关联到一些其他表。我想在执行 CreateUser 方法后立即重定向到 AccountCreated 视图(不想等到 UpdateUserIDInRelatedTables() 方法完成执行。有什么想法吗?(在 C# 4,MVC3 中)
【问题讨论】:
-
您使用的是哪个版本的 .Net? 3.5 还是 4?
-
我不相信您可以使用任何多线程选项,但是您可以使用 JQuery 异步调用方法。但是我不确定这对你有帮助。
-
我觉得它可以正常工作,但是成功响应
AccountCreated为时过早,你为什么这么确定UpdateUserIDINRelatedTables方法不会出现错误? -
@GarrettFogerlie:我正在寻找像异步这样的服务器端解决方案。不是javascript
标签: asp.net-mvc-3 asynchronous parallel-processing