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 7759615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:40:31+00:00 2026-06-01T13:40:31+00:00

I have a class that requires dynamically setting a List. I also call this

  • 0

I have a class that requires dynamically setting a List. I also call this class 10 or so different times using Threading.

public static List<string> MyList {get;set;}

I’m new to threading, however, as I’ve been told this is unsafe. The question I have is how do I make an instance of MyList per thread?

An example would be awesome!

  • 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-06-01T13:40:32+00:00Added an answer on June 1, 2026 at 1:40 pm

    Use the ThreadStatic attribute.

    [ThreadStatic] private static List<string> _myList;
    
    public static List<string> MyList {
      get { return _myList; }
      set { _myList = value; }
    }
    

    Also, usually it’s better for the containing class to have control over the collection; this would mean no externally-visible setter and a getter that returns either a copy or a read-only collection.

    But, this might not have the effect you intend. Each thread will have its own copy of the collection. Maybe what you need is to take a look at locks or rethink your design.

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

Sidebar

Related Questions

Let's say I have a class that requires configuration, dependency injection etc. public class
I have a class that requires a specific method to be called before being
I have a class that executes the MSNP15 protocol. The protocol requires clients to
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate
I'd like to call methods of a class dynamically with parameter values that are
I have controls that are dynamically added via javascript. I cannot set the class
I'm currently developing a web application using Struts2 framework. This application requires to dynamically
I have a custom class loader so that a desktop application can dynamically start
Is there a way to require that a class have a particular abstract member?

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.