icecreamsoop
icecreamsoop

Reputation: 129

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?

Upvotes: 1

Views: 668

Answers (1)

Steven
Steven

Reputation: 172786

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.

Upvotes: 2

Related Questions