Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What thread-safe collection classes are available in Silverlight 4?

I am developing an application framework that will be utilized by Silverlight on the client side and .NET 4 on the server side. Internally, the framework has dictionary and queue data structures where multiple threads will be accessing the collections concurrently.

On the server side, I would like to utilize the ConcurrentDictionary and ConcurrentQueue classes available in the System.Collections.Concurrent namespace. These classes however are not implemented in Silverlight 4.

The two approaches I am considering are:

  1. Decompile the ConcurrentDictionary and ConcurrentQueue classes and implement them in a Silverlight class library. These would be scoped using the System.Collections.Concurrent namespace.
  2. Implement the custom thread-safe collection classes I need in a shared library (or find a reliable Silverlight thread-safe collection implementation) that can be used both server and client side.

The first approach would allow me to just implement the Silverlight data structures that I need, but I worry about introducing disparities between my Silverlight implementation and the concurrent collection classes implemented in .NET 4.

The second approach would provide a consistent concurrent collection implementation both client and server side, but feels like I would be reinventing the wheel.

It does not appear that implementing the ConcurrentDictionary and ConcurrentQueue classes in Silverlight would be very difficult, but is there already a well adopted library of thread-safe collection classes for Silverlight?

like image 452
Oppositional Avatar asked May 02 '11 15:05

Oppositional


People also ask

Which of the following are thread-safe collection?

The collection classes that are thread-safe in Java are Stack, Vector, Properties, Hashtable, etc.

Are C# lists thread-safe?

The ConcurrentBag class is used to create a thread-safe, unordered collection of data in C#. The ConcurrentBag class is very similar to the List in C# and can be used as a thread-safe list in C#.

Is .NET list thread-safe?

NET Framework 4 introduces the System. Collections. Concurrent namespace, which includes several collection classes that are both thread-safe and scalable. Multiple threads can safely and efficiently add or remove items from these collections, without requiring additional synchronization in user code.


2 Answers

The class library for Mono includes implementations of the various concurrent collections, and is licensed under the very permissive MIT license.

like image 42
Sam Harwell Avatar answered Sep 20 '22 17:09

Sam Harwell


Try this out: http://ch.codeplex.com/

like image 149
hazzik Avatar answered Sep 21 '22 17:09

hazzik