Cache per Thread

A

anassar

I have an ASP.Net Web Application where I depended on Sessions to share
information across the code. One of the buttons the user clicked, take
a long time to process. So, I started multi-threading the function
behind that button, but then I hit a brick wall - the new thread has no
access to Context.Current and therefore cannot see the Session
variables.

I understand why threads should not depend on Context.Current as they
can outlive the context's lifespan. I also understand that I can pass
the User Information that was stored in a Session as a parameter to my
thread. The problem is that I have 100's of functions I wrote that
depended on Session and now I have to go through all of them to
accomodate the thread limitation.

My question is: Is there a Cache I can depend on at the thread level to
store User Information that I can share and access from all of my
functions ?

BTW, I use classes within classes so I have several levels on hierarchy
and passing information down/up that tree is non-trivial. I am looking
for cache that I can access from anywhere on that thread.

I have a unique ID per thread. So, one thing I thought of doing is to
put a HashTable on the Application stack in Global.asax where the key
is that Unique ID. But then how do I propagate that Unique ID
throughout all the functions in that thread ? I still come to the same
problem - I need some cache space that can be accessed from any
function or class on that thread.

Please help as I have spun my wheels for days now.

Aladdin
 
G

Guest

Aladdin,
At first blush it sounds like you might really be shooting yourself in the
foot here.
"Multithreading" Button clicks in a ASP.NET application, where the page
class itself has an extremely limited lifetime, is likely to be fraught with
all kinds of additional problems besides just the fact that the button click
"takes a long time to process".

You could use Remote Scripting (AJAX) to do the processing from the button -
click asynchronously, and if you use the right infrastructure ("Anthem.net"
or "MagicAjax") for example, you would still have access to the statefulness
of the page (including Session).

Hope it helps, just my 2 cents.
Peter
 
A

anassar

Peter:

That is an excellent idea, I never thought of. I am a novice to Ajax.
Can you please give me a basic example that posts to an aspx page
asynchronously with query string parameters ?

On a seperate note, for my sanity, is there such a thing thread-wide
cache in ASP.Net or is cache only at the application level ? And what
is the best way to share data between different classes with several
levels down besides passing parameters ?

Thank you very much for your response,

Aladdin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top