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

  • SEARCH
  • Home
  • 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 7009149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:34+00:00 2026-05-27T21:49:34+00:00

I was wondering if this statement would cause sync issues: List<Character> characters = World.CharacterManager.Characters;

  • 0

I was wondering if this statement would cause sync issues:

List<Character> characters = World.CharacterManager.Characters;

‘Characters’ is a class

‘CharacterManager.Characters’ would look something like this:

public List<Character> Characters
{
    get
    {
        lock (this.objLock) { return this.characters; }
    }
}

would this cause synchronization problems?

I want to use the referenced List to iterate through to find the character I am looking for.

  • 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-27T21:49:35+00:00Added an answer on May 27, 2026 at 9:49 pm

    The lock is useless that way. You will have to use a thread-safe collection such as Will suggested, or if you don’t need write access you can expose only a read only version of your list like so:

    public ReadOnlyCollection<Character> Characters {
      get {
        lock (locker) { return this.characters.AsReadOnly(); }
      }
    }
    

    These collections cannot be modified, so if your Character type is immutable, you don’t have any synchronization issues. If Character is mutable, you have again a problem, but you would have that problem even with a thread-safe collection. I hope you’re aware of that. You can also expose the property returning an IList<Character>, but usually I find it better to tell the caller that the object is read only.

    If you need write access, you could also do that by providing the appropriate methods at the scope of the CharacterManager and synchronize them. Jesse has written a nice example on how to do this.

    EDIT: SyncRoot is not present on ICollection<T>.

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

Sidebar

Related Questions

I was always wondering about this seemingly utopic world of open source. Assuming the
Just wondering... I find using escape characters too distracting. I'd rather do something like
I'm wondering where a switch statement of this style should be changed to an
I'm wondering what would be considered best practise for this. It's fairly inconsequential but
I am wondering if something like this could be done(of course what I have
This is part of a larger statement, but I'm wondering if CTE or another
I've been wondering this for a while but since it hasn't come up much
I've been wondering this for some time. As the title say, which is faster,
Wondering if this is possible. We have an 3rd Party library that contains identification
Just wondering is this kind of code recommended to increase performance? void functionCalledLotsofTimes() {

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.