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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:43:28+00:00 2026-06-05T04:43:28+00:00

I have a class like this. public abstract class HtmlObject<T> { public HtmlObject() {}

  • 0

I have a class like this.

public abstract class HtmlObject<T>
{

    public HtmlObject() {}
    public HtmlObject(string id, string name, T value)
    {
        this.ID = id;
        this.Name = name;
        this.Value = value;
    }

    public string ID { get; set; }
    public string Name { get; set; }
    public T Value { get; set; }

    public abstract string Build();
}

With a concrete implementation that looks like this.

public class HtmlRadio : HtmlObject<string>
{
    private const string RadioHtml = "<input type='radio' name='{0}' value='{1}' {2} />{1}<br />";

    public bool Checked { get; set; }

    public override string Build()
    {
        if (this.Checked) 
            return string.Format(HtmlRadio.RadioHtml, this.Name, this.Value, "checked='checked'");
        else
            return string.Format(HtmlRadio.RadioHtml, this.Name, this.Value, string.Empty);
    }
}

And what I want to know is if the call to Build() would be safe if made across threads. My assumption is it wouldn’t because if I take the following series of calls

HtmlRadio radio = new HtmlRadio();
radio.Checked = false;
//Something could happen here?
string result = radio.Build();

My understanding is that the value of radio.Checked could change between it being set and the call to Build(), is this correct? If so how could I ‘fix’ this if I wanted to?

  • 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-05T04:43:30+00:00Added an answer on June 5, 2026 at 4:43 am
    IHtmlRadio radio = new HtmlRadio();
    radio.Checked = false;
    //Something could happen here only if you give `radio` to another thread somehow.
    string result = radio.Build();
    

    Is another thread able to access radio? If not, then you are fine.

    In addition, what are you afraid of? If checked changes from false to true or true to false, do you really care? It’s not going to blow up – it will return a boolean, not throw an exception.

    Edit: No, it is not thread-safe as written, another thread could change Checked and Value and Name, none of which are protected in any way in any order.

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

Sidebar

Related Questions

I have a class like this public abstract class BaseType<T> { public string Name
I have a situation like this: public abstract class BaseClass { public abstract string
I have a model that looks something like this: public abstract class Parent {
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
Consider this abstract class public abstract class Foo { public Injectable Prop {get;set;} }
I have an abstract class BaseItem declared like this: public abstract class BaseItem {
I have something like this: public abstract class Menu { public Menu() { init();
If I have an abstract class like this: public abstract class Item { private
Suppose I have something like this: public abstract class AbstractDataObject { public abstract void
I have a model (simplified for relevance) like this: public abstract class TitleCreateModel :

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.