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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:50:44+00:00 2026-05-23T20:50:44+00:00

In MSDN some .NET classes described like this: This type is thread safe. or

  • 0

In MSDN some .NET classes described like this:

“This type is thread safe.”

or

“Public static (Shared in Visual Basic) members of this type are thread safe. Instance members are not guaranteed to be thread-safe.”.

My question is which features make a class to be thread-safe?

  • Is there any standard, recommendation or guidelines for thread-safety programming?

  • When I use lock(C#) keyword, it means my class is thread-safe or not?

  • How to I evaluate thread-safety of a class? Is there any TESTS to be sure that a class is 100% thread safe?

Example:

public class MyClass
{
    public void Method()
    {
        lock (this)
        {
            // Now, is my class 100% thread-safe like Microsoft classes?
        }
    }
    type m_member1;
    type m_member2;
}

thanks

  • 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-23T20:50:44+00:00Added an answer on May 23, 2026 at 8:50 pm

    A class is generally considered thread-safe if its methods can be invoked by multiple threads concurrently without corrupting the state of the class or causing unexpected side-effects. There are many reasons why a class may not be thread safe, although some common reasons are that it contains some state that would be corrupted on concurrent access.

    There are a number of ways to make a class thread-safe:

    1. Make it immutable, if a class contains no state it is safe to use concurrently from multiple threads.
    2. Employ locking to reduce concurrency. However, this is no guarantee of thread safety, it just ensures that a block of code will not be executed concurrently by multiple threads. If state is stored between method invocations this might still become inconsistent.

    How you create a thread-safe class really depends on what you want to do with the class in question.

    You also need to ask yourself, do I need to make my class threadsafe? a common model of most UI frameworks is that there is a single UI thread. For example in WinForms, WPF and Silverlight the majority of your code will be executed from the UI thread which means you do not have to build thread-safety into your classes.

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

Sidebar

Related Questions

I'm working through some MSDN examples, and some books on ADO.Net. What they all
Some 4 years back, I followed this MSDN article for DateTime usage best practices
Now CAPICOM is deprecated, and MSDN recommends to use .net classes from System.Security.Cryptography. But
Recently I had to type up some documentation on .net data providers and ado.net.
I've been following this guide from MSDN about Creating an ASP.NET MVC Areas Application
I'm a little confused. In many tutorials, including some in MSDN and ASP.NET website,
See this MSDN post for some background: Using metadata to call a target multiple
I read some articles in MSDN magazine about new features in ASP.NET AJAX 4.0
i've been reading through the linq to xml documentation in msdn and some other
According to MSDN BOL (Books Online) description on SOME | ANY (Transact-SQL) , SOME

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.