I have an application that has a list of objects stored in a static ConcurrentBag
.
The UI has a timer that runs methods that can update the objects in the ConcurrentBag
.
Only one thread (Started by the timer) will try to update these objects. However, this thread will enumerate through the list and then update the items as it goes.
At the same time these objects can be read by the UI thread.
ConcurrentBag
is working perfectly for what I want to do. All the business logic is in a separate project and I now need to port everything to iOS and Android. I'm doing this with Xamarin and so am converting the business logic into a Portable Class Library.
Although everything I'm targeting appears to support ConcurrentBag
, when I try to access it in a PCL, System.Collections.Concurrent
is not available. Even if I only target .net 4.5 and above + windows store apps (Both of which I have used ConcurrentBags
for)
Is there another alternative to ConcurrentBag
or am I better off just creating separate projects for each targeted system?
ConcurrentBag
in my code. As long as you don't target Windows Phone or Silverlight, I think you should have no problems usingConcurrentBag
in your PCL.System.Collections.Concurrent
namespace is not included in any WP version, including 8.1. By the way, it seems odd that you cannot accessConcurrentBag
on VS 2013 Update 1 as long as you avoid the WP/Silverlight targets? Have you double-checked that it is not working on Update 1 even when you target .NET 4, Windows (Store) 8, Xamarin.Android and Xamarin.iOS?ConcurrentBag
, so I assume that at least in (the current) PCL set-up you will not be able to include WP 8.1 target. Regarding documentation, I checked the list of namespaces here. Of course, I am not 100% sure that this list is up-to-date.