【发布时间】:2014-04-13 04:13:54
【问题描述】:
在以下代码中,_uow(工作单元)的线程 ID 和哈希值在调用 await 之前和之后是相同的。如果请求线程被释放,为什么延续请求线程的id相同?为什么与请求线程关联的_uow对象有相同的hash id,就像线程状态被释放到线程池中却保持一样?
public AccountController(IUow uow)
{
_uow = uow;
}
public async Task<ActionResult> Sample()
{
int id1 = Thread.CurrentThread.ManagedThreadId;
int hash1 = _uow.GetHashCode();
await SignInAsync(account, isPersistent: false);
int id2 = Thread.CurrentThread.ManagedThreadId; //same as id1
int hash2 = _uow.GetHashCode(); //same as hash1
return Content("");
}
【问题讨论】:
标签: c# asp.net-mvc async-await