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


C# Subject.Sample方法代码示例

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


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

示例1: interval_is_cancelled_on_completion

        public void interval_is_cancelled_on_completion()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnCompleted();
            scheduler.RunNext();

            Assert.AreEqual(0, scheduler.QueueSize);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:18,代码来源:SampleFixture.cs

示例2: Run

        public static void Run()
        {
            var source = new Subject<int>();

            source
                .Sample(TimeSpan.FromSeconds(1.0))
                .Subscribe(x => Console.WriteLine($"received {x}"))
                ;

            var t = new Thread(() =>
            {
                var i = 0;
                while (true)
                {
                    Thread.Sleep(250);
                    source.OnNext(i);
                    Console.WriteLine($"sent {i}");
                    i++;
                }
            });
            t.Start();
        }
开发者ID:amq,项目名称:oom,代码行数:22,代码来源:PushExampleWithSubject.cs

示例3: Start

        /// <summary>
        /// Start a new session
        /// </summary>
        public SessionId Start(SessionId sessionId, int timeoutSeconds, Map<string,object> initialState)
        {
            lock (sync)
            {
                if (sessions.ContainsKey(sessionId))
                {
                    return sessionId;
                }
                var session = SessionVector.Create(timeoutSeconds, VectorConflictStrategy.First, initialState);
                sessions = sessions.Add(sessionId, session);

                // Create a subject per session that will buffer touches so we don't push too
                // much over the net when not needed.  This routes to a single stream that isn't
                // buffered.
                var touch = new Subject<Tuple<SessionId, DateTime>>();
                touch.Sample(TimeSpan.FromSeconds(1))
                     .ObserveOn(TaskPoolScheduler.Default)
                     .Subscribe(touched.OnNext);
                sessionTouched = sessionTouched.Add(sessionId, touch);
            }
            return sessionId;
        }
开发者ID:OlduwanSteve,项目名称:language-ext,代码行数:25,代码来源:SessionSync.cs

示例4: SampleCompletesWhenBothSequencesComplete

            public void SampleCompletesWhenBothSequencesComplete()
            {
                var left = new Subject<int>();
                var right = new Subject<int>();

                var result = left.Sample(right).Materialize().CreateCollection();

                left.OnNext(1);
                left.OnCompleted();

                right.OnNext(1);
                right.OnCompleted();

                Assert.Equal(new[] { Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>() }, result);
            }
开发者ID:mdabbagh88,项目名称:ReactiveMarrow,代码行数:15,代码来源:ObservableExtensionsTest.cs

示例5: last_value_from_timeout_period_is_used

        public void last_value_from_timeout_period_is_used()
        {
            TestScheduler scheduler = new TestScheduler();

            Subject<int> subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            subject.Sample(TimeSpan.FromSeconds(1), scheduler).Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            scheduler.RunTo(TimeSpan.FromMilliseconds(200).Ticks);

            subject.OnNext(2);
            subject.OnNext(3);
            scheduler.RunTo(TimeSpan.FromMilliseconds(1000).Ticks);

            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(3, stats.NextValues[0]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:21,代码来源:SampleFixture.cs

示例6: uses_scheduler_to_schedule_samples

        public void uses_scheduler_to_schedule_samples()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            Assert.AreEqual(1, scheduler.QueueSize);

            subject.OnNext(0);
            scheduler.RunNext();

            Assert.AreEqual(1, scheduler.QueueSize);
            Assert.AreEqual(1, stats.NextCount);
            Assert.AreEqual(0, stats.NextValues[0]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:21,代码来源:SampleFixture.cs

示例7: no_value_is_emitted_if_sampled_value_hasnt_changed

        public void no_value_is_emitted_if_sampled_value_hasnt_changed()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            stats.OnNext(0);

            scheduler.RunNext();
            scheduler.RunNext();

            Assert.AreEqual(1, stats.NextCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:19,代码来源:SampleFixture.cs

示例8: last_value_is_taken_for_each_sample

        public void last_value_is_taken_for_each_sample()
        {
            var subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var scheduler = new ManualScheduler();

            subject
                .Sample(TimeSpan.FromSeconds(1), scheduler)
                .Subscribe(stats);

            subject.OnNext(0);
            subject.OnNext(1);
            scheduler.RunNext();

            subject.OnNext(2);
            subject.OnNext(3);
            scheduler.RunNext();

            Assert.AreEqual(2, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.AreEqual(3, stats.NextValues[1]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:24,代码来源:SampleFixture.cs

示例9: StartProcessing

        private void StartProcessing()
        {
            if (IsKinectPaused)
            {
                IsKinectPaused = false;
            }

            var observableColorAndDepth = Observable.FromEventPattern<MultiSourceFrameArrivedEventArgs>(KinectManager.Instance, "ColorAndDepthSourceFrameArrived");

            ColorAndDepthSourceSubscription = observableColorAndDepth
                .Do(_ =>
                {
                    ++totalColorAndDepthFrames;
                    ++colorAndDepthFrames;

                    if (colorAndDepthFPSTimer.ElapsedMilliseconds >= 1000)
                    {
                        ColorAndDepthFramesPerSec = colorAndDepthFrames;
                        colorAndDepthFrames = 0;
                        colorAndDepthFPSTimer.Restart();
                    }
                })
                .ObserveOn(NewThreadScheduler.Default)
                .Subscribe(
                e => ColorAndDepthSourceFrameArrived(e.Sender, e.EventArgs)
            );

            observableColorData = new Subject<byte[]>();
            observableDepthData = new Subject<ushort[]>();
            observableDepthSpaceData = new Subject<DepthSpacePoint[]>();

            // -- Set up Automatic thresholding --

            var ExecuteAutomaticThreshold = ReactiveCommand.CreateAsyncTask(param =>
            {
                var input = param as ushort[];

                return AutomaticThreshold(input);
            });

            AutoThresholdSubscription = observableDepthData
                .Sample(TimeSpan.FromSeconds(1))
                .Where(_ => AutomaticThresholds)
                .InvokeCommand(ExecuteAutomaticThreshold);

            ExecuteAutomaticThreshold
                .Subscribe((t) =>
                {
                    FarThreshold = t;
                    NearThreshold = t - 500; // Nearthreshold is 50 cm towards the camera.
                });

            // --
            // -- Set up Filtering --

            FilterFramesSubscription = observableColorData
                .Zip(observableDepthData, observableDepthSpaceData, (c, d, dsp) => Tuple.Create(c, d, dsp))
                .InvokeCommand(ExecuteFilterVideoFrame);

            // --
        }
开发者ID:jtpgames,项目名称:Kinect-Recorder,代码行数:61,代码来源:FilterKinectViewModel.cs


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