Parallel.ForEach error HttpContext.Current

前端 未结 4 1433
猫巷女王i
猫巷女王i 2021-01-02 09:43

this method - doDayBegin(item.BranchId) is taking long time to execute. So I am using Parallel.ForEach to execute it parallel. When I am using norm

4条回答
  •  悲哀的现实
    2021-01-02 10:12

    You get the error because you are trying to get the HttpContext from a thread that is not running for the purpose of responding to a request.

    The HttpContext.Current property uses the thread to identify which context to get, as the web server can run several threads to handle requests. As the Parallel.ForEach starts new threads, they will not be connected to a HttpContext.

    You need to pass along the information that the method needs in the call to the method.

提交回复
热议问题