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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:08:00+00:00 2026-06-01T01:08:00+00:00

What are the implications of the using the Lazy<T> class and marking isThreadSafe: false

  • 0

What are the implications of the using the Lazy<T> class and marking isThreadSafe: false during initialization?

In a scenario where lazy needs to access instance members and not static members where the lazy is initialized inside the class constructor does this automatically require isThreadSafe: false in all usages?

  • 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-01T01:08:02+00:00Added an answer on June 1, 2026 at 1:08 am

    In a scenario where lazy needs to access instance members and not static members where the lazy is initialized inside the class constructor does this automatically require isThreadSafe: false in all usages?

    No – The isThreadSafe argument only affects how the value within the Lazy<T> is created.

    Basically, when you set it to false, the method to create the value will just create the value, set it to the internal storage, and return the value.

    If you set it to true, then the creation will be wrapped inside of a lock, preventing more than one thread from ever creating the object. This maps to LazyThreadSafetyMode.ExecutionAndPublication.

    You can also specify PublicationOnly explicitly, which will allow more than one value to be created, but then use an Interlocked.CompareExchange internally instead of a lock to make sure that the first completed creation routine’s value is the one that’s used for the object.

    Note that none of these options has any affect at all on which members are used for computing the value – they only affect how the value itself is created. The access for everything other than creation is always thread safe. If you’re initializing a Lazy<T> instance member within a class constructor, you’re effectively guaranteeing that there will be no synchronization required, so you could set isThreadSafe to false – but that would also mean that there is absolutely no reason to use Lazy<T> in this situation, since you’re using explicit instantiation…

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

Sidebar

Related Questions

Are there any implications of using SqlDependency and LINQ to SQL together. Or do
I realize that, generally speaking, there are performance implications of using reflection. (I myself
I'm looking into the exact implications of using QueryPerformanceCounter in our system and am
What are the implications of using the xml: namespace? I'm talking about the difference
I was wondering if there were any performance implications between using TPL TaskFactory.FromAsync and
I was wondering what the implications are for using static methods in a Java
Are there any implications to using default values, such as empty strings, when inserting
What are the implications of using a half-duplex serial connection versus a full-duplex one?
Can someone explain the implications of using with (nolock) on queries, when you should/shouldn't
I was wondering what were the hidden performance implications of using the Database object

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.