开发者

How do I access System.Web.Http.Current.Response from a within a thread?

开发者 https://www.devze.com 2023-01-07 20:42 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消