Cache per Thread

Discussion in 'ASP .Net' started by anassar, Jan 6, 2006.

  1. anassar

    anassar Guest

    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
    anassar, Jan 6, 2006
    #1
    1. Advertising

  2. 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

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "anassar" wrote:

    > 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
    >
    >
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 6, 2006
    #2
    1. Advertising

  3. anassar

    anassar Guest

    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
    anassar, Jan 7, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S01aX3N0YXRl?=

    Quick one - Is SESSION per browser instance or per IP Address?

    =?Utf-8?B?S01aX3N0YXRl?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,860
    gerry
    Apr 10, 2006
  2. Razvan
    Replies:
    1
    Views:
    399
    tony vee
    Sep 10, 2004
  3. Replies:
    5
    Views:
    2,518
  4. Replies:
    0
    Views:
    339
  5. liu yang
    Replies:
    4
    Views:
    1,991
    Antoninus Twink
    Jul 28, 2008
Loading...

Share This Page