解决办法:

<httpRuntime targetFramework="4.5" />

或者:

In your appSettings, set aspnet:UseTaskFriendlySynchronizationContext to true.

2. 在非Http请求线程中使用为空

示例代码——将主线程的HttpContext传递进去:

var httpContext = HttpContext.Current;

TaskWithDuration = new Task<long>(() =>
{
    var sw = new Stopwatch();
    sw.Start();

    HttpContext.Current = httpContext;

    action();

    sw.Stop();

    return sw.ElapsedMilliseconds;
});

REF:

[HttpContext.Current并非无处不在] http://www.cnblogs.com/fish-li/archive/2013/04/06/3002940.html

相关文章:

  • 2022-12-23
  • 2022-02-06
  • 2022-02-25
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-08-07
  • 2021-12-26
  • 2021-07-16
  • 2021-09-24
  • 2022-12-23
  • 2021-07-20
  • 2021-06-19
相关资源
相似解决方案