Intermittent Bug - Subscribers are missing values, w code and screenshot

Sep 11, 2013 at 2:31 AM
Here is my code.

            numbers = Observable.Generate(DateTime.Now, 
                                            time => true,
                                            time => DateTime.Now,
                                            time => { return new Random(DateTime.Now.Millisecond).NextDouble() * 99 + 2; },
                                            time =>TimeSpan.FromSeconds(1.0));


            numbers.ObserveOnDispatcher()
                .Subscribe(s => list1.Items.Add(s.ToString("##.00")));

            numbers.Where(n => n < 10).ObserveOnDispatcher().
                Subscribe(s => list2.Items.Add(s.ToString("##.00")));
See the screen shot. 3.76 is missing from the Left list
Image
Sep 11, 2013 at 2:31 AM
Here is the link for Screenshot, http://postimg.org/image/wqrj20rdp/
Sep 11, 2013 at 4:37 AM
Hi,

Generate returns a cold observable. In your example, each time that you subscribe you get a new random sequence. If you want to broadcast the sequence to multiple subscribers then add Publish. You must then either call Connect after subscribing or simply apply the RefCount operator.

For details see my blog post on Hot and Cold Observables.
var p = numbers.Publish();

p.ObserveOnDispatcher().Subscribe(s => list1.Items.Add(s.ToString("##.00")));

p.Where(n => n < 10).ObserveOnDispatcher().Subscribe(s => list2.Items.Add(s.ToString("##.00")));

p.Connect();
- Dave
Sep 11, 2013 at 7:19 AM