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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:14:57+00:00 2026-05-15T15:14:57+00:00

I’m not sure what to do as far as managing the _namePrefixes for this

  • 0

I’m not sure what to do as far as managing the _namePrefixes for this control. I know I can make it non-static, but it makes sense to be static to be consistent across all uses of this control in terms of content for my project. Also, I chose ObservableCollection because of the following scenario:

I have 2 client machines, one for standard use, the other for managing options (admin) such as a Name Prefix list. If the client is running and the admin makes a change, the client should update itself and reflect those changes after it has already been loaded. Oh, and because this is a WPF item and I wanna databind it to a ListBox. If neither of these make me use an ObserableCollection, no big deal… I’ll use something like a List, but I don’t think that’ll change the original question.

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MyProject
{

    public class NameField : TextBox
    {
        private static ObservableCollection<NamePrefix> _namePrefixes;
        private static ObservableCollection<NameSuffix> _nameSuffixes;

        static NameField()
        {
            _namePrefixes = new ObservableCollection<NamePrefix>();
            _nameSuffixes = new ObservableCollection<NameSuffix>();
        }

        public static void AddNamePrefix(Int32 id, String prefix)
        {
            //TODO: WHAT DO I DO HERE!?
        }

    }

    /// <summary>
    /// A Key/Value structure containing a Name Prefix ID and String value.
    /// </summary>
    public struct NamePrefix
    {
        #region Constructor

        public NamePrefix(Int32 id, String prefix)
            : this()
        {
            ID = id;
            Prefix = prefix;
        }

        #endregion

        #region Properties (ID, Prefix)

        public Int32 ID { get; set; }
        public String Prefix { get; set; }

        #endregion
    }

    /// <summary>
    /// A Key/Value structure containing a Name Suffix ID and String value.
    /// </summary>
    public struct NameSuffix
    {
        #region Constructor

        public NameSuffix(Int32 id, String suffix)
            : this()
        {
            ID = id;
            Suffix = suffix;
        }

        #endregion

        #region Properties (ID, Prefix)

        public Int32 ID { get; set; }
        public String Suffix { get; set; }

        #endregion
    }
}
  • 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-15T15:14:58+00:00Added an answer on May 15, 2026 at 3:14 pm

    If what you’re looking to do is avoid adding the same actual instance to the collection multiple times because of threaded operations overlapping, then the standard solution for this is to do the work inside of a lock block.

    public static void AddNamePrefix(NamePrefix prefix)
    {
        lock(_namePrefixes)
        {
            if(!_namePrefixes.Contains(prefix)) _namePrefixes.Add(prefix);
        }
    }
    

    (and the same for suffixes)

    Locks are single-use resources, so when a thread has a lock on an object (in this case, the collection), then any other thread attempting to acquire the lock will be blocked until the existing lock is released. The upshot in this scenario is that only one thread will be able to execute the code inside the lock block at any given time; all others will wait until the current thread finishes, then proceed on one by one.

    It’s worth noting that the object used to lock does not have to have anything to do with the operations taking place inside of the block. As long as the locks attempt to lock on the same object, then this will work. It’s a common practice to declare a dedicated instance of type object to lock on, but in this case the collection can serve that purpose.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.