MVC2.0中的AsyncController

时间:2012-10-30 09:55:34

标签: c# asp.net-mvc-2 asynccontroller

这是我在MVC 2.0中尝试的东西

public class SomeController : AsyncController
{  
    public void SampleAsync()
    {
        AsyncManager.OutstandingOperations.Increment();
        for(int i=0; i=100000; i++)
        {
        // Some Code... This loop is just for the testing.
        }
        AsyncManager.OutstandingOperations.Decrement();        
    }

    public ActionResult SampleCompleted(ActionResult result)
    {
        return result;
    }
}
  1. 我的问题是这里SampleCompleted的参数是什么 这是ACTIONRESULT。我试图找出但我会发现的每一个地方 找到了不同的东西那究竟是什么?
  2. 我是否需要在Global.ascx文件中进行更改。喜欢 RouteCollection.MapRoute到RouteCollection.AsyncMapRoute

1 个答案:

答案 0 :(得分:0)

  1. SampleCompleted的参数或参数将是您在AsyncManager.Parameters中指定的变量 - 集合:
  2. 例如:

    public void SampleAsync()
        {
            AsyncManager.OutstandingOperations.Increment();
            for(int i=0; i=100000; i++)
            {
    
            }
            AsyncManager.Parameters["myvariable"] = "variable value";
            AsyncManager.OutstandingOperations.Decrement();        
        }
    
        public ActionResult SampleCompleted(string myvariable)
        {
            //myvariable contains value "variable value"
            return result;
        }
    

    2。您无需进行更改。

相关问题