当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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?

分享给朋友:
您可能感兴趣的文章:
随机阅读: