Debian Codegraph @

external/rx/Rx/NET/Samples/HOL/CS/Excercise5/Step05/Program.cs

raw
1 using System;
2 using System.Reactive;
3 using System.Reactive.Linq;
4 using System.Windows.Forms;
5
6 namespace Excercise5
7 {
8 class Program
9 {
10 static void Main()
11 {
12 var txt = new TextBox();
13
14 var frm = new Form()
15 {
16 Controls = { txt }
17 };
18
19 var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
20 select ((TextBox)evt.Sender).Text)
21 .LogTimestampedValues(x => Console.WriteLine("I: " + x.Timestamp.Millisecond + " - " + x.Value))
22 .Throttle(TimeSpan.FromSeconds(1))
23 .LogTimestampedValues(x => Console.WriteLine("T: " + x.Timestamp.Millisecond + " - " + x.Value))
24 .DistinctUntilChanged();
25
26 using (input.Subscribe(inp => Console.WriteLine("User wrote: " + inp)))
27 {
28 Application.Run(frm);
29 }
30
31 }
32 }
33
34 public static class MyExtensions
35 {
36 public static IObservable<T> LogTimestampedValues<T>(this IObservable<T> source, Action<Timestamped<T>> onNext)
37 {
38 return source.Timestamp().Do(onNext).Select(x => x.Value);
39 }
40 }
41 }