| 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 |
|
| 15 |
namespace SilverlightApplication |
| 16 |
{ |
| 17 |
public partial class MainPage : UserControl |
| 18 |
{ |
| 19 |
public MainPage() |
| 20 |
{ |
| 21 |
InitializeComponent(); |
| 22 |
Loaded += new RoutedEventHandler(MainPage_Loaded); |
| 23 |
} |
| 24 |
|
| 25 |
void MainPage_Loaded(object sender, RoutedEventArgs e) |
| 26 |
{ |
| 27 |
var portableClass = new PortableClassLibrary.PortableClass(); |
| 28 |
|
| 29 |
// Create timer and route output to list1 |
| 30 |
portableClass.CreateTimer(10, TimeSpan.FromSeconds(1.5)) |
| 31 |
.Buffer(2) |
| 32 |
.ObserveOnDispatcher() |
| 33 |
.Subscribe(items => |
| 34 |
{ |
| 35 |
foreach (var item in items) |
| 36 |
list1.Items.Add(item); |
| 37 |
}, onCompleted: () => |
| 38 |
{ |
| 39 |
list1.Items.Add("Finished"); |
| 40 |
}); |
| 41 |
|
| 42 |
// Create list observer and route output to list1, but specify scheduler instead of using SubscribeOnDispatcher |
| 43 |
var scheduler = System.Reactive.Concurrency.DispatcherScheduler.Current; |
| 44 |
portableClass.CreateList(scheduler) |
| 45 |
.Delay(TimeSpan.FromSeconds(1)) |
| 46 |
.ObserveOn(scheduler) |
| 47 |
.Subscribe(item => |
| 48 |
{ |
| 49 |
list2.Items.Add(item); |
| 50 |
}, onCompleted: () => |
| 51 |
{ |
| 52 |
list2.Items.Add("Finished"); |
| 53 |
}); |
| 54 |
|
| 55 |
|
| 56 |
} |
| 57 |
} |
| 58 |
} |