MainPage.xaml.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using System.Reactive;
  13. using System.Reactive.Linq;
  14. namespace SilverlightApplication
  15. {
  16. public partial class MainPage : UserControl
  17. {
  18. public MainPage()
  19. {
  20. InitializeComponent();
  21. Loaded += new RoutedEventHandler(MainPage_Loaded);
  22. }
  23. void MainPage_Loaded(object sender, RoutedEventArgs e)
  24. {
  25. var portableClass = new PortableClassLibrary.PortableClass();
  26. // Create timer and route output to list1
  27. portableClass.CreateTimer(10, TimeSpan.FromSeconds(1.5))
  28. .Buffer(2)
  29. .ObserveOnDispatcher()
  30. .Subscribe(items =>
  31. {
  32. foreach (var item in items)
  33. list1.Items.Add(item);
  34. }, onCompleted: () =>
  35. {
  36. list1.Items.Add("Finished");
  37. });
  38. // Create list observer and route output to list1, but specify scheduler instead of using SubscribeOnDispatcher
  39. var scheduler = System.Reactive.Concurrency.DispatcherScheduler.Current;
  40. portableClass.CreateList(scheduler)
  41. .Delay(TimeSpan.FromSeconds(1))
  42. .ObserveOn(scheduler)
  43. .Subscribe(item =>
  44. {
  45. list2.Items.Add(item);
  46. }, onCompleted: () =>
  47. {
  48. list2.Items.Add("Finished");
  49. });
  50. }
  51. }
  52. }