当前位置: 首页>>代码示例>>C#>>正文


C# Subject.TimeInterval方法代码示例

本文整理汇总了C#中Subject.TimeInterval方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.TimeInterval方法的具体用法?C# Subject.TimeInterval怎么用?C# Subject.TimeInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.TimeInterval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TimeBetweenCalls

        public void TimeBetweenCalls()
        {
            var received = new List<String>();
            var events = new Subject<String>();
            events.TimeInterval().Where(t => t.Interval.TotalMilliseconds > 100).Subscribe(s => received.Add(s.Value));
            events.OnNext("too");
            events.OnNext("fast");
            Thread.Sleep(120);
            events.OnNext("slow");
            Thread.Sleep(120);
            events.OnNext("down");

            Assert.AreEqual("slow down", String.Join(" ", received));
        }
开发者ID:alwalker,项目名称:rx_koans,代码行数:14,代码来源:Lesson4Time.cs

示例2: Run1

        void Run1()
        {
            /*
            disposable?.Dispose();

            done.Text = "Working...";
            var now = new DateTimeOffset(0, TimeSpan.FromTicks(0)) + TimeSpan.FromMinutes(10);
            var sequences = Program.GetStuff2();
            Func<Thing, Thing, int> comparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
            var stuff = new TrackingCollection<Thing>(sequences,comparer,
                (t, idx, col) => idx >=5 && idx < 10
                //&& t.CreatedAt > now && t.CreatedAt <= (now + TimeSpan.FromMinutes(10))
                );
            //list.ItemsSource = stuff;
            disposable = stuff.Subscribe(() =>
            {
                bool bad = false;
                //stuff.SetComparer(OrderedComparer<Thing>.OrderBy(x => x.Number).Compare);
                for (int i = 0; i < stuff.Count - 1; i++)
                {
                    if (comparer(stuff[i], stuff[i + 1]) > 0)
                    {
                        bad = true;
                        break;
                    }
                }
                if (bad)
                    done.Text = "Problem";
                else
                    done.Text = "Done";
            });
            */

            var seq = Program.GetStuff(50);

            //var col = new TrackingCollection<Thing>(
            //    OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);
            //var res = col.Listen(seq);
            //col.ProcessingDelay = TimeSpan.FromMilliseconds(20);

            //col.CollectionChanged += (s, ee) => {
            //    //Console.WriteLine(ee.Action);
            //    ee.NewItems?.OfType<Thing>().All(thing => { Console.WriteLine("{0} {1}:{2}", ee.Action, thing.Number, thing.UpdatedAt); return true; });
            //};

            list.ItemsSource = col;
            //res.TimeInterval()
            //    .Select(i => log.Text += i.Interval + "\r\n")
            //    .Subscribe();
            Subject<DateTime> times = new Subject<DateTime>();
            var count = 0;
            double time = 0;
            times.TimeInterval().Do(i =>
            {
                count++;
                time += i.Interval.TotalMilliseconds;
                log.Text += i.Interval + "\r\n";
            }).Subscribe(_ => { }, () => Debug.WriteLine("AVERAGE " + time / count));

            var res = col.Listen(seq);
            Debug.WriteLine("===== GO ======");
            col.OriginalCompleted.Subscribe(_ => { }, () => times.OnCompleted());
            col.Subscribe(x => times.OnNext(DateTime.Now), () => times.OnCompleted());

            //seq.Subscribe();
            //foreach (var x in seq.ToEnumerable())
            //{
            //    col.AddItem(x);
            //}
        }
开发者ID:shana,项目名称:handy-things,代码行数:70,代码来源:MainWindow.xaml.cs


注:本文中的Subject.TimeInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。