G
Guest
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;
}
}
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;
}
}