Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4081502
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:04:09+00:00 2026-05-20T18:04:09+00:00

I am calling from one piece of my code through several layers of 3rd

  • 0

I am calling from one piece of my code through several layers of 3rd party code, and the call surfaces back into my code at some point by calling some code I’ve written.

In other words, the code call chain looks like this:

My code #1 --> 3rd party code --> My code #2

Unfortunately, nothing I pass to the 3rd party code is given to that second piece of code so I have nothing to tie the first piece and the second piece together, except for the fact that the code runs on the same thread.

So I was wondering if simply using [ThreadStatic] on a static field on a class would be a viable solution to this?

Since the code also runs in a web application, I cannot just use a static field for this, since the value I need access to (an object) is different for each user/session.

ie. I would do something like this:

internal static class DataHolder
{
    [ThreadStatic]
    internal static ClassName FieldName;
}

Are there other solutions to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:04:10+00:00Added an answer on May 20, 2026 at 6:04 pm

    In contrast to the other answers suggesting that this is ok, you should be very careful about using ThreadStatic or ThreadLocal<T> in an ASP.NET application.

    ASP.NET utilises thread-agility, meaning that the same request can potentially be handled by several threads. To be safe you’d need to break encapsulation and store your items in the current HttpContext, rather than using ThreadStatic or ThreadLocal<T>:

    internal static class DataHolder
    {
        internal static ClassName PropertyName
        {
            get { return (ClassName)System.Web.HttpContext.Current.Items["foo"]; }
            set { System.Web.HttpContext.Current.Items["foo"] = value; }
        }
    }
    

    Unfortunately this thread-agility “feature” is very poorly documented. I’m reasonably sure that the thread switch can only happen at certain points in the lifecycle, not arbitrarily, so depending on exactly how and where in the lifecycle the code is used you might be safe with ThreadStatic or ThreadLocal<T>.

    I’ll try to dig out some links…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem in the code below is calling one function from another - the
I am getting a SerializationException for an enum when calling from one AppDomain into
I'm getting some unexpected results calling one makefile from another. I have two makefiles,
I am using this code phone calling from iPhone its calling directly to particular
Is it possible to hide the number you are calling from through Android's SDK?
I have an old, third party, command line, proprietary program which I'm calling from
I'm working with a legacy piece of code in some stuff for work which
I have one ASP.NET Webservice that i calling from my Android app and getting
I followed the below steps. 1.I am calling 2 exes(b&c) from one exe(a) which
How to explain callbacks in plain English? How are they different from calling one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.