The cross-thread usage of “HttpContext.Current” property and related things

前端 未结 3 626
执念已碎
执念已碎 2020-11-27 13:39

I read from < Essential ASP.NET with Examples in C# > the following statement:

Another useful property to know about is the static Current property

3条回答
  •  广开言路
    2020-11-27 14:05

    The backing field of Current is marked as ThreadStatic (I assume), hence it wont be available/initialized in user-created threads.

    What it comes down to is, that you should capture the instance of HttpContext.Current in the request thread and then use that instance in your threads, instead of referring to HttpContext.Current.

提交回复
热议问题