Пример #1
0
        public IObservable <double> WhenReadingTaken()
        {
            this.observable = this.observable ?? Observable.Create <double>(ob =>
            {
                var handler = new EventHandler <TemperatureSensorDataUpdatedEventArgs>((sender, args) =>
                                                                                       ob.OnNext(args.Temperature)
                                                                                       );
                var sensor = new TemperatureSensor
                {
                    Interval = 250
                };
                sensor.DataUpdated += handler;
                sensor.Start();

                return(() =>
                {
                    sensor.Stop();
                    sensor.DataUpdated -= handler;
                    sensor.Dispose();
                });
            })
                              .Publish()
                              .RefCount();

            return(this.observable);
        }