473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

HttpContext.Current is null in asynch method?

I'm trying call a couple WebRequests asynchronously using the
QueueUserWorkItem, but one thing I noticed is that the HttpContext is null
within the asynchronous call. I was using HttpContext.Current.Server.MapPath
to load an Xslt file to format and return Xml after the webrequest is made.

Is there a way around this?

Here some code...

stateInfo = new StateInfo(manualEvents[0], strUrl);
System.Threading.ThreadPool.QueueUserWorkItem(new
WaitCallback(this.MyWebRequestCallback), stateInfo);

private void MyWebRequestCallback(object state)
{
StateInfo stateInfo = (StateInfo)state;
MakeWebRequestAndTransformXML(stateInfo.Url); <--NULL where this calls
Server.MapPath
stateInfo.manualEvent.Set();
}

class StateInfo
{
public string Url;
public ManualResetEvent manualEvent;

public StateInfo(ManualResetEvent manualEvent, string Url)
{
this.manualEvent = manualEvent;
this.Url = Url;
}
}
Nov 19 '05 #1
1 4249
Dave wrote:
I'm trying call a couple WebRequests asynchronously using the
QueueUserWorkItem, but one thing I noticed is that the HttpContext is
null within the asynchronous call. I was using
HttpContext.Current.Server.MapPath to load an Xslt file to format and
return Xml after the webrequest is made.

Is there a way around this?

Here some code...

stateInfo = new StateInfo(manualEvents[0], strUrl);
System.Threading.ThreadPool.QueueUserWorkItem(new
WaitCallback(this.MyWebRequestCallback), stateInfo);

private void MyWebRequestCallback(object state)
{
StateInfo stateInfo = (StateInfo)state;
MakeWebRequestAndTransformXML(stateInfo.Url); <--NULL where this
calls Server.MapPath
stateInfo.manualEvent.Set();
}

class StateInfo
{
public string Url;
public ManualResetEvent manualEvent;

public StateInfo(ManualResetEvent manualEvent, string Url)
{
this.manualEvent = manualEvent;
this.Url = Url;
}
}


HttpContext is quite likely a thread-local object. You could make the
HttpContext part of the StateInfo, but I'm not sure about HttpContext's
lifecycle and if it can be used across threads.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Inochkin | last post by:
Hi! Could you help me to understand next fact... I open in LDASM System.Web.dll and read: ..method /*060002D7*/ public hidebysig specialname static class System.Web.HttpContext/* 02000051...
2
by: moondaddy | last post by:
I need to set a variable to a session variable (if that's what you call it) like this: dim ds as dataset = HttpContext.Current.Session("CustDataSet") But I get an exception if this variable...
5
by: coollzh | last post by:
who can tell the detailed difference of: HttpRuntime, Context, HttpContext.Current sometimes, we can use Context Object instead of HttpContext.Current; sometimes, we can user HttpRuntime...
3
by: Steve Lutz | last post by:
Hello All, I have an ASPX page whose class inherits from a company global base page. The company base page has a property call PageTitle (string) that is assigned by all the pages. The base...
0
by: Aaron Morton | last post by:
I'm working on a IHttpModule that handles the PreSendRequestHeaders event from the HttpApplication, if the event is raised after EndRequest then HttpContext.Current is null. If it is raised before...
4
by: Sami Rehman | last post by:
hi i have a vs solution in which there are 2 projects class library representing Security services and another one is web application project. i need to access http context in a static method in...
2
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
14
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.