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

  • Home
  • SEARCH
  • 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 40365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:00:44+00:00 2026-05-10T15:00:44+00:00

I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but

  • 0

I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but the same method isn’t available on Queue<T>. Does anyone know why? Seems kind of weird.

  • 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. 2026-05-10T15:00:45+00:00Added an answer on May 10, 2026 at 3:00 pm

    Update – in .NET 4, there now is ConcurrentQueue<T> in System.Collections.Concurrent, as documented here http://msdn.microsoft.com/en-us/library/dd267265.aspx. It’s interesting to note that its IsSynchronized method (rightly) returns false.

    ConcurrentQueue<T> is a complete ground up rewrite, creating copies of the queue to enumerate, and using advanced no-lock techniques like Interlocked.CompareExchange() and Thread.SpinWait().

    The rest of this answer is still relevant insofar as it relates to the demise of the old Synchronize() and SyncRoot members, and why they didn’t work very well from an API perspective.


    As per Zooba’s comment, the BCL team decided that too many developers were misunderstanding the purpose of Synchronise (and to a lesser extent, SyncRoot)

    Brian Grunkemeyer described this on the BCL team blog a couple of years back: http://blogs.msdn.com/bclteam/archive/2005/03/15/396399.aspx

    The key issue is getting the correct granularity around locks, where some developers would naively use multiple properties or methods on a ‘synchronized’ collection and believe their code to be thread safe. Brian uses Queue as his example,

    if (queue.Count > 0) {     object obj = null;     try {         obj = queue.Dequeue(); 

    Developers wouldn’t realize that Count could be changed by another thread before Dequeue was invoked.

    Forcing developers to use an explicit lock statement around the whole operation means preventing this false sense of security.

    As Brian mentions, the removal of SyncRoot was partly because it had mainly been introduced to support Synchronized, but also because in many cases there is a better choice of lock object – most of the time, either the Queue instance itself, or a

    private static object lockObjForQueueOperations = new object(); 

    on the class owning the instance of the Queue…

    This latter approach is usually safest as it avoids some other common traps:

    • Never lock(this)
    • Don’t lock(string) or lock(typeof(A))

    As they say, threading is hard, and making it seem easy can be dangerous.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer JSyntaxPane is decent. Advanced and decent IDEs use either Lexer/Parsers… May 11, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer Nothing. Leave it as #define MY_API and all instances of… May 11, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer It is mod_security's 10_asl_rules.conf causing this error. May 11, 2026 at 11:29 pm

Related Questions

When you use DllImport to import a function you can specify a CharSet to
I've been working on a DirectX application in C#, and I noticed that when
I've got a problem with a SOAP Web Reference that was generated by Visual
I was working in the Microsoft.Ink dll recently using C# and was debugging a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.