Rx .Net TestScheduler-执行立即安排的事件 [英] Rx .Net TestScheduler- executing immediately scheduled events

查看:141
本文介绍了Rx .Net TestScheduler-执行立即安排的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当我这样做时:

   testScheduler   时间表  "Hello world" ,(  scheduler    state      =>    控制台   WriteLine   状态 ));   
testScheduler
AdvanceTo testScheduler 现在 );



我在  VirtualTimeSchedulerBase

   public    无效    AdvanceTo    TAbsolute  时间   
{
int num = 这个 Comparer 比较 时间 时钟 );
如果 num < 0
抛出 ArgumentOutOfRangeException " time" );
如果 num == 0
返回 ;



num
== 0
 为真,退出方法。



我可以打电话  testScheduler.Start() 和
我的操作将会执行。但是然后  TestScheduler  将
继续执行其队列中的所有内容。而我希望它在当前时间停止执行操作。



我在TestScheduler上看不到任何能让我得到我想要的行为的方法。



这是一个错误,还是正确的行为,但我错过了什么?

解决方案

显然,TestScheduler只执行一次动作现在是_after_预定时间。


所以我需要AdvanceTo(dueTime + 1)。


When I do this:

testScheduler.Schedule("Hello world",(scheduler, state) => Console.WriteLine(state));
testScheduler.AdvanceTo(testScheduler.Now);

I hit this code in VirtualTimeSchedulerBase:

public void AdvanceTo(TAbsolute time)
{
  int num = this.Comparer.Compare(time, this.Clock);
  if (num < 0)
    throw new ArgumentOutOfRangeException("time");
  if (num == 0)
    return;

num == 0 is true, and I exit the method.

I can call testScheduler.Start() and my action will execute. But then TestScheduler will carry on executing everything in its queue. Whereas I want it to stop executing actions at the current time.

I can't see any other methods on TestScheduler that will get me the behaviour I want.

Is this a bug, or is it the correct behaviour but I'm missing something?

解决方案

Evidently TestScheduler only executes actions once Now is _after_ the scheduled time.

So I need to AdvanceTo(dueTime+1).


这篇关于Rx .Net TestScheduler-执行立即安排的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆