Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2006

Tip: Looking for answers? Try searching our database.

OS Thread unable to access Session variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Diffident - 26 Nov 2006 23:06 GMT
Hi All,

I am trying to perform a non-CPU bound operation in an asynchronous fashion
using 'Thread' and a delegate. Basically, I am spawning a thread using
ThreadStart and Thread.

My non-CPU bound operation needs to have access to Session variables; Even
though I embedded the state information (which also includes the context
object) in an object and passed the object to the Thread , I am unable to
access the Session variables. The system throws a Null Object Reference error.

Since the thread that I am spawning is not from the CLR thread pool, it is
not able to access the Session variable. Am I right? How can a system thread
get access to the Session variables of the current HTTPRequest?

Here is what I am trying to do (in C#):

=====

ThreadStart t = new ThreadStart(LongDBProcess)
// LongDBProcess is a  time-consuming process
Thread ts = new Thread(t);
t.start();         //At this point, system thread will be created and not
the CLR thread

====

I need to have access to Session variables inside my LongDBProcess...

private void LongDBProcess()
{
   Session["IDCounter"] = i+1;           //At this point, I am getting null
reference
}

If I am correct, the thread is not able to access the session. Probably this
thread's scope is outside the Application Domain whereas the session data
will be inside the Application Domain...am I correct?

Thanks for your pointers.

I hope I articulated my problem. If not, please let me know.

Any pointers will be appreciated!
David Browne - 27 Nov 2006 01:48 GMT
> Hi All,
>
[quoted text clipped - 39 lines]
> thread's scope is outside the Application Domain whereas the session data
> will be inside the Application Domain...am I correct?

No.  Same app domain.  But Session scope is tied to the thread executing the
page request.   You can pass to the thread a reference to an object also
contained in session scope, but the background thread can't find objects in
the session scope directly.

David

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.