c# - ConnectableObservable 一次处理所有订阅的方法?

标签 c# timer system.reactive

所以我有一个游戏服务器,每个玩家都有一个计时器,比如:

this.player.Timer = from tick in TimerPublisher where tick % 1 == 0 select tick;

我有一些订阅方法,例如:

this.player.Timer.Subscribe( tick => IncreseStamina() );
this.player.Timer.Subscribe( tick => IncresePower() );
//etc

所以我想做的不是设置

IDisposable dis = //the subscribed method;

所以我可以说

dis.Dispose(); //so it Dispose that method 

我想立即处理所有订阅的方法,我可以这样做吗?

最佳答案

试试这个:

IDisposable dis = new CompositeDisposable(new []
{
    this.player.Timer.Subscribe(tick => IncreseStamina()),
    this.player.Timer.Subscribe(tick => IncresePower()),
    //etc
});

然后你可以这样写:

dis.Dispose();

简单吧?

关于c# - ConnectableObservable 一次处理所有订阅的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7423612/

相关文章:

c# - C#读取和解析Excel文件

c# - 检测页面是否在 iframe 中 - 服务器端

c# - 哪个网页元素标签更适合使用 Webdrive 定位和获取值(value)

快速倒数计时器 - 显示剩余的天数小时秒数

c# - Reactive Extension 能否捕获/检测连续的案例?

c# - 第一次异常 - System.pdb 未加载

java - 特定日期和时间的倒计时器

java - 为什么这个简单的调度程序不起作用?

c# - 奇怪的 Rx+CancellationToken 问题 : sometimes the registered callback does not complete

c# - 可观察管道中的异常处理