【问题标题】:How to execute a method asynchronously in MVC 3?如何在 MVC 3 中异步执行方法?
【发布时间】: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


【解决方案1】:

试试异步控制器。 这可能会帮助你 http://msdn.microsoft.com/en-us/library/ee728598(v=vs.100).aspx

【讨论】:

    猜你喜欢
    • 2012-07-14
    • 2014-07-17
    • 2019-04-21
    • 2015-07-05
    • 2019-01-19
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多