Cezary Piątek Blog
Read post

Avoid multithreading traps with Roslyn: Lock object selection

Learn about the traps to avoid in multithreading with Roslyn analyzers. Avoid locking on publicly accessible members or this reference. Do not lock on objects with weak identity, non-readonly fields, or value types. Follow the best practice of creating a private and readonly instance of an object for locking.

    #.net#c#
May 04, 2024•5m read time•From cezarypiatek.github.io
Post cover image
Table of contents
DO NOT lock on publicly accessible members 🔗︎DO NOT lock on this reference 🔗︎DO NOT lock on objects with weak identity 🔗︎DO NOT lock on non-readonly fields 🔗︎DO NOT lock on value types 🔗︎Best practice for locking 🔗︎Summary 🔗︎
1 Impression
Cezary Piątek Blog's image
Cezary Piątek Blog

3 Followers

•

4 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard