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?
精彩评论