1. 程式人生 > >Controller中添加一個異步的Action

Controller中添加一個異步的Action

col task ive new 示例 ask action str tro

給一段示例代碼:

        public Task<ActionResult> TbReport(string code)
        {
            return Task.Factory.StartNew(() =>
            {
                ...
                return View(report);
                ...
                return View("");//未找到子報表
            }).ContinueWith<ActionResult>(task =>
            {
                
return task.Result; }); }

以上代碼 StartNew() 括號中去異步執行,ContinueWith()執行完畢後返回值。


完整資料請訪問:ASP.NET MVC下的異步Action的定義和執行原理

Controller中添加一個異步的Action