Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

HttpContext.Current function returns Nothing for spawned thread

  Asked By: Jody    Date: May 11    Category: Asp.net    Views: 3505
  

It appears that when a thread is spawned from an ASP.NET page, the
HttpContext.Current function returns Nothing.

Given that, is it possible to retrieve a reference to the Session
object in a non-Page function calling it from a spawned thread?

A simplified version of the code to reproduce this would be as
follows:



Public Class WebForm1
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CallTestSessionStateSet()
Dim oThread As New System.Threading.Thread(AddressOf
CallTestSessionStateSet)
oThread.Priority = Threading.ThreadPriority.BelowNormal
oThread.Start()
End Sub

Public Sub CallTestSessionStateSet()
TestSessionStateSet("test1")
End Sub
End Class

Module modGlobal

Public Sub TestSessionStateSet(ByVal tValue As String)
HttpContext.Current.Session("test") = tValue
End Sub

End Module


When this is run, the call to TestSessionStateSet within the
Page_Load runs just fine, but an exception occurs when it is called
from the spawned thread. The exception is a NullReferenceException
error since HttpContext.Current is Nothing

Any ideas as to how to access the current Session from the non-Page
function?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: