Program.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reactive.Linq;
  6. namespace Net40ConsoleApplication
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. var portableClass = new PortableClassLibrary.PortableClass();
  13. var scheduler = System.Reactive.Concurrency.CurrentThreadScheduler.Instance;
  14. // Create timer and route output to console
  15. portableClass.CreateTimer(10, TimeSpan.FromSeconds(1.5))
  16. .Buffer(2)
  17. .ObserveOn(scheduler)
  18. .Subscribe(items =>
  19. {
  20. Console.WriteLine(" 1: Received items {0}", string.Join(", ", items));
  21. }, onCompleted: () =>
  22. {
  23. Console.WriteLine(" 1: Finished ");
  24. });
  25. // Create list observer and route output to console, but specify scheduler instead of using SubscribeOnDispatcher
  26. portableClass.CreateList(scheduler)
  27. .Delay(TimeSpan.FromSeconds(1))
  28. .Subscribe(item =>
  29. {
  30. Console.WriteLine(" 2: Received item {0}", item);
  31. }, onCompleted: () =>
  32. {
  33. Console.WriteLine(" 2: Finished ");
  34. });
  35. Console.WriteLine("Press enter to exit");
  36. Console.ReadLine();
  37. }
  38. }
  39. }