通過Visual Studio的Controller創建向導創建的Controller類型實際上繼承自抽象類System
public abstract class Controller :
ControllerBase
IController
IAsyncController
IActionFilter
IAuthorizationFilter
IExceptionFilter
IResultFilter
IDisposable
…
{
//省略成員
}
同步還是異步
從抽象類Controller的定義可以看出它同時實現了IController和IasyncController這兩個接口
如下面的代碼片段所示
public abstract class Controller: …
{
//其他成員
protected virtual bool DisableAsyncSupport
{
get{return false;}
}
protected virtual IAsyncResult BeginExecute(RequestContext requestContext
AsyncCallback callback
{
if (this
{
//通過調用Execute方法同步執行Controller
}
else
{
//通過調用BeginExecuteCore/EndExecuteCore方法異步執行Controller
}
}
protected virtual IAsyncResult BeginExecuteCore(AsyncCallback callback
object state)
protected virtual void EndExecuteCore(IAsyncResult asyncResult)
}
現在我們通過一個簡單的實例來演示屬性DisableAsyncSupport對默認創建的Controller執行的影響
[
From:http://tw.wingwit.com/Article/program/net/201311/16097.html