开发者

ConnectableObservable Dispose all the subscribed methods at once?

开发者 https://www.devze.com 2023-04-05 03:31 出处:网络
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;

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

精彩评论

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