O'Reilly logo

.NET Design Patterns by Shine Xavier, Praseed Pai

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting entities to streams (IObservable<T>)

The following constructs can be converted to a sequence source. IObservable<T> can be generated from the following:

  • Events
  • Delegates
  • Tasks
  • IEnumerable<T>
  • Asynchronous programming model

Converting events into stream

We have now understood how one can convert an IEnumerable<T>-based pull program to an IObservable<T>/IObserver<T>-based push program. In real life, the event source is not as simple as we found in the number stream example given previously. Let us see how we can convert a MouseMove event into a stream with a small WinForms program:

 static void Main() { var mylabel = new Label(); var myform = new Form { Controls = { mylabel } }; IObservable<EventPattern<MouseEventArgs>> mousemove = Observable. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required