I'm just trying to do a simple event handler on a string variable, so that if the string changes, it will do a Console.WriteLine (using the new Reactive library from MS (Rx))
The issue that I have is that it will display the first bit when I instantiate the class ("RandomGuid : Mine?"), but after that, none of the stuff I change afterwards spits anything out to the console.
I went through the HOL from the MS website, but it goes straight from defining the Observable into reading values from a textbox, when all I want to do is watch whether a string was changed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MynahBirds
{
class Program
{
static void Main(string[] args)
{
List<Minah> minahs = new List<Minah>();
for (int i = 0; i < 10; i++) {
minahs.Add(new Minah());
}
foreach (var item in minahs) {
item.peers = minahs;
}
minahs.ForEach(m => m.s = Observable.Return<string>("Mine"));
minahs.ForEach(m => m.s = Observable.Return<string>("Whee"));
minahs.ForEach(m => m.s = Observable.Return<string>("Argh"));
Console.ReadLine();
}
}
class Minah
{
Guid Id;
public List<Minah> peers;
IDisposable subscription;
public IObservable<string> s = Observable.Return<string>("Mine?");
public Minah()
{
try {
this.Id = Guid.NewGuid();
subscription = s.Subscribe((string a) => {
Console.WriteLine("{0} : {1}", this.Id, a);
},
(Exception ex) => {
Console.WriteLine("Error {0} hit", ex.ToString());
},
() => { });
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
Console.ReadLine();
throw;
}
}
}
}