Program.cs 1.1 KB

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