Software Architecture – C# 4.0 – New Feature – Synchronized Data Structures – Thread Safe Queue

In c# 4.0, Microsoft has introduced a new namespace with name “System.Collections.Concurrent” which provide set of collections having thread safe behavior.

Some of these thread safe collections are as:

Class
BlockingCollection<T>
ConcurrentBag<T>
ConcurrentDictionary<TKey, TValue>
ConcurrentQueue<T>
ConcurrentStack<T>
OrderablePartitioner<TSource>
Partitioner
Partitioner<TSource>

 Lets take example of example of Queue data structure, Simple queue is explained here

http://msdn.microsoft.com/en-us/library/system.collections.queue.aspx

The generic version of queue is explained here.

http://msdn.microsoft.com/en-us/library/7977ey2c.aspx

Before arrival of C# 4.0, thread safety in queue was ensured by using Queue.Synchronized as explained at:

http://msdn.microsoft.com/en-us/library/system.collections.queue.synchronized.aspx

But now we have better implementation of thread safe queue with System.Collections.Concurrent namespace, as explained here:

http://msdn.microsoft.com/en-us/library/dd267265.aspx

Advertisements

6 Responses to Software Architecture – C# 4.0 – New Feature – Synchronized Data Structures – Thread Safe Queue

  1. Peter Gfader says:

    These new types rock!

    Did you already use them in a project?

    CU
    .peter.gfader.
    http://blog.gfader.com/
    http://twitter.com/peitor

  2. shahzadsb says:

    This namespace is really good addition to .net family.

    Yes, in all the new projects. We heavy insist developers to use them.

    Saw your blog… interesting stuff.

    Shahzad
    http://www.shahzadsb.com

  3. Peter Gfader says:

    Thx

    What I love about this new Concurrent types is that
    #1 Code is much easier to write without locks in place
    #2 Readability is so much better without locks

  4. Dobeoblilla says:

    Hi, it’s nice here so I am just saying hi. I’ve been reading forums for a month now and decided to register. Hope that my english will be good enough to communicate with you :). My hobby are airplanes and my hobby page – http://www.aviao.pl – bilety lotnicze it’s about them.

  5. fungusnails says:

    פטרת הינה בעיה נפוצה במיוחד בקרב האוכלוסיה ולי יש המלצה לפתרון:
    חדשנות בטיפול בפטרת ציפורניים
    הריגת פטרת השוכנת מתחת לציפורניים,
    בשנים האחרונות התפתח תחום הטיפול בפטרת ציפורניים.
    שיטה חדשנית תעזור לכם
    בחיסול הפטריות
    אני ממליצה בחום על פטרת קליניק כמרפאה המובילה לחיסול פטרת ציפורניים בלייזר.
    ביטחון מלא בהצלחת הטיפול!
    ניתן לזהות בכמה דרכים מתי אדם סובל מפטרת
    סירחון, שינוי צבע הציפורן לגוון צהוב או סגול.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: