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