首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AsyncController AsyncManager参数问题

AsyncController AsyncManager参数问题
EN

Stack Overflow用户
提问于 2012-08-06 23:02:54
回答 1查看 1.2K关注 0票数 0

我正在用一个异步控制器做一些测试,我有以下代码:

代码语言:javascript
复制
public class AsyncSampleController : AsyncController
{

     public void IndexAsync()
      {
           Tasks tasks = new Tasks();
           //Indicates that we already started an asynchronous operation
           AsyncManager.OutstandingOperations.Increment();
           //Task.Factory start new to use another thread to use our operation.
           Task.Factory.StartNew(() =>
           {
                Stopwatch s1 = Stopwatch.StartNew();        
                tasks.BigOperation();
                s1.Stop();
                long data=s1.ElapsedMilliseconds;
                AsyncManager.Parameters.Add("data",data);
            });
            AsyncManager.OutstandingOperations.Decrement();

       }
       public ActionResult IndexCompleted(long data)
       { 
           ViewBag.ElapsedTime = data.ToString();
           return View();
       }
}

问题是BigOperation方法多花了一秒钟或少花了一秒,但我没有得到存储在IndexCompleted操作的data参数上的已用时间值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-07 20:12:18

我没有对此进行测试,但是您应该将Decrement调用放入您的匿名任务中。我猜测Decrement是在任务完成之前调用的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11830865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档