开发者

ConnectableObservable Dispose all the subscribed methods at once?

so i have a game server every player has a开发者_如何学编程 timer so like:

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

and i have some subscribed methods like:

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

so what i want to do is instead of setting

IDisposable dis = //the subscribed method;

so i can say

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

i want away to Dispose all my subscribed methods at once can i do that?


Try this:

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

Then you can write:

dis.Dispose();

Easy, huh?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜