c# - ConcurrentBag Alternative In Portable Class Library -
I have an application that contains a list of objects stored in static concurrentabs.
UI is a timer that runs methods that can update the object in concurrently.
Only one thread (started by the timer) will attempt to update these objects. Although this thread will tell through the list and then it will update according to the item.
At the same time these objects can be read by the UI thread.
The concurrent bag is working perfectly, I have a mind to do. All business logic is in a separate project and now I have to port everything for iOS and Android. I am doing this with exploitation and therefore I am converting business logic into a portable class library.
However, the targeting that I support supports the concurrent bag, when I try to access it in PCL system, the compilation is not available. Even if I have targeted only 4.5 4.5+ and the Windows + Store app (both I have used a concurrent bag for both), even then
if another for a concurrent bug Is Option or Are I Just Creating Different Projects for Each Targeted System?
OK, if it does not work, you have several options here. First of all, delete the concurrent bank and use that code. Second, to come up with a replacement, it is my guess that you do not need the necessary performance guarantees in your specific case and there is a need to order the issues of concurrent bag ... So, it's a fit to fit your bill. Example:
Namespace nive (using system; using System.Collections.Generic; using System.Collections.ObjectModel; public class ThreadSafe CollectionNow & lt; T & gt; { Private redoni list & lt; T & gt; _list = New list & lt; T & gt; (); Private readonly object _craticalSection = new object (); /// & lt; summary & gt; /// It consumes in UI. It is O (n) /// & lt; / summary & gt; Public readline compilation & lt; T & gt; GetContentsCopy () {lock (_criticalSection) {return new list & lt; T & gt; (_ list). Es readonly (); }} /// & lt; Summary & gt; /// This is a way to handle this update, do not want to write many code /// & lt; / summary & gt; Public Zero update (action & lt ; List & lt; T & gt; workToDoInTheList} {if (workToDoInTheList == empty) Throw new logic to "workToDoInTheList"; Lock (_criticalSection) {workToDoInTheList.Invoke (_list); }} Public int calculation {get {lock (_criticalSection) {return_list.Count; }}} // As you are seeing, add more members} class program {static wide main (string [] arg) {var archives = new threadsoff collectionNow & lt; String & gt; (); CollectionNaive.Update ((L) = & gt; L. Adrange (new [] {"1", "2", "3"})); CollectionNaive.Update ((l) = & gt; {for (int i = 0; i & lt; l.Count; i ++) {if (L [i] == "1") {l [i] = "15";}}}); }}}
Comments
Post a Comment