c# - Events vs. Yield -


I have a multi-threaded application that produces threads for many hardware devices. Each thread basically has an infinite loop (For the lifetime of the application) which selects the hardware for new data, and each time when something new collects, then activates an event (which passes through data) is a single audience category that all these Consolidates the devices, makes some calculations And removes a new event with this calculation.

However, I am thinking that, because there is a listener, it will be a IEnumerable & lt; & Gt; Better to expose the method, and use yield returns to return data instead of firing event.

I would like to see if any one of these two methods is aware of the difference or not. In particular, I am looking for the best ability to best reliability, prevention / cancellation ability, purpose of threading, general safety, etc.

Also, with the second method it is still possible to run IEnumerable loop on a separate thread? Many of these devices are CPU-bound to some extent, so it is important to ensure that each one is placed on different threads.

For reactive extensions this sounds like a very good use case, but there is a little learning curve In short, IObservable, IEnumerable is dual where IEnumerable requires you to pull it from, pushing your values ​​supervisor to IObservable. You have to be blocked at any time in your enumerator, this is a good sign, you should reverse the pattern and use a push model. Incidents are a way to go but IObservable has more flexibility because it is compose-worthy and thread-aware.

  Devices DataAventants Where (x = & gt; x.SomeProperty == something). BufferWithtimeSpain.FormsCondus (1)) subscribe (x => DodothhingWith (x));  

In the above example, DoSomethingWith (x) will also be called when the topic (instrument) creates a data event that has some matching properties and this event can be used for 1 second period Buffers in batches. / P>

There is too much you can do, such as merge into events created by other topics or directing information on the UI thread. Unfortunately the documentation is currently very weak but it has some good information. (Although his post almost mentions reactive extensions for Javascript, but it is also highly applicable to NAT on Reactive Extensions.)


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -