C#: Adding context to Parallel.ForEach() in ASP.NET

后端 未结 4 1847
甜味超标
甜味超标 2020-12-16 00:42

I have a static class with a static get property, and in this property, I do this:

// property body
{
    // HttpContext.Current is NOT null
    ...

    Par         


        
4条回答
  •  萌比男神i
    2020-12-16 01:16

    It does not work, because inside the foreach, a new thread is created, so the context is null. Even creating a method DoSomething to set the curren context, the context is still null.

提交回复
热议问题