How do I access System.Web.Http.Current.Response from a within a thread?
I have a ASP.NET page with a WebMethod that creates an object and runs one of the object's methods in a new thread.
I need to access the System.Web.HttpContext.Current.Response.ContentType
property 开发者_运维问答from within this thread.
Each time I (try to) access it, I receive a NullReferenceException
.
Is this posible?
The HttpContext.Current
returns the instance for the current thread. Since you are executing in another thread, you can't access it this way. Try to pass the ContentType
to your thread, but be careful in passing a HttpResponse
object to another thread, since it is not thread-safe.
精彩评论