【发布时间】:2014-07-03 23:52:25
【问题描述】:
我正在寻找我会调用CounterObservable 的东西,一侧将计算其上的数字,另一侧将是观察者一侧,每次总计数发生变化时都会收到通知。
换句话说,我会有这样的东西
public CounterObservable totalMailsReceived = new CounterObservable(0);
public void OnNewMail(Mail mail)
{
totalMailsReceived++;
///Rest of the code goes here
}
在观察者方面,我将拥有
mailManager.totalMailsReceived.Subscribe(count => labelCount.Text = count.ToString());
或者,如果我想要真正优雅,我会使用 Paul Betts 的 ReactiveUI,如下所示
mailManager.totalMailsReceived.ToProperty(x => x.TotalMailsReceived);
到目前为止,我在 Rx 中没有发现任何可以帮助我的东西。但我想如果我创建自己的类来实现IObservable<int>。我正在考虑使用Sample MSDN Code for IObservable implementation。
我的问题是 1. 那是MSDN Sample 线程安全的吗? 2. Rx 中真的没有任何东西可以做我想做的事情吗?
【问题讨论】:
标签: system.reactive reactive-programming