Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat type of IProducerConsumerCollection<T> to use for my task?
    text
    copied!<p>I have exactly 100 Sensors each "measuring" own data. I have exactly one <em>DataSender</em> which should send information from "sensors". The most recent information should be sent.</p> <p>Bandwidth of the channel may be less than data produced by 100 sensors. In this case some data can be skipped - but we should be "roughly fair". For example, we could skip every second measurement from each sensor.</p> <p>I don't know how often each sensor generates data, but in general they generate data pretty often.</p> <p>After my other posts:</p> <ul> <li><a href="https://stackoverflow.com/questions/5801952/how-to-create-singleton-which-always-running-in-separate-thread">how to create singleton which always running in separate thread?</a></li> <li><a href="https://stackoverflow.com/questions/5842553/modified-producer-consumer-example-any-problems-with-it">Modified Producer/Consumer example, any problems with it?</a></li> </ul> <p>I have decided that I have classical <strong>Producer/Consumer</strong> problem, with:</p> <ul> <li>100 Producers, and</li> <li>1 Consumer</li> </ul> <p>I've been suggested to use <a href="http://msdn.microsoft.com/en-us/library/dd997371.aspx" rel="nofollow noreferrer"><code>BlockingCollection</code></a> for this. The only problem with <code>BlockingCollection</code> - once you have added item, you cannot <strong>replace</strong> it. But in my application, if sensor produces a new value, and previous value was not processed by the <code>Consumer</code>, the value should be <strong>replaced</strong>.</p> <p>Should I use use a <a href="https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx" rel="nofollow noreferrer"><code>ConcurentDictionary</code></a> or <a href="https://msdn.microsoft.com/en-us/library/dd381779(v=vs.110).aspx" rel="nofollow noreferrer"><code>ConcurentBag</code></a> for that task?</p> <p>Conceptually, <strong>all I need</strong> is an array of 100 elements.</p> <p>Sensor #33 should <strong>replace</strong> it's value into array[33]:</p> <pre><code>| Sensor | Value | |--------|-------| | 1 | | | 2 | | | 3 | | /......../......./ | 32 | | | 33 | 101.9 | | 34 | | /......../......./ | 98 | | | 99 | | | 100 | | </code></pre> <p><code>Consumer</code> should take value from <code>array[33]</code> and if not null, then send it and set array[33] to null. <code>Consumer</code> should react on any not null values in array asap.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload