Looking at http://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx, it seems that ConcurrentDictionary
and all of its friends in the System.Collections.Concurrent
namespace are available for use in a Portable Class Library.
However, when I create either an F# or C# Portable Class Library, even if I explicitly add a reference to mscorlib.dll
, the compilation fails when using ConcurrentDictionary
.
Why?
NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.
The Portable Class Library project enables you to write and build managed assemblies that work on more than one . NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.
ConcurrentDictionary<TKey,TValue> is designed for multithreaded scenarios. You do not have to use locks in your code to add or remove items from the collection. However, it is always possible for one thread to retrieve a value, and another thread to immediately update the collection by giving the same key a new value.
Class libraries are the shared library concept for . NET. They enable you to componentize useful functionality into modules that can be used by multiple applications. They can also be used as a means of loading functionality that is not needed or not known at application startup.
The term "Portable" should be loosely applied right now. When you create the class library project, you get prompted for the targets you want to support. You'll only get ConcurrentDictionary when you select ".NET Framework" and ".NET for Windows Store apps".
Pick any other and the entire namespace disappears.
This will get better over time, I'd assume, but Windows Phone 7, XBox and Silverlight are lagging behind right now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With