Odysseyx.net 例子——(1)基础【分分快三计

作者:编程技术

2、Timer使用

1、订阅序列

分分快三计划 1

例子来自

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;

namespace SimpleSequence
{
    class Program
    {
        static void Main(string[] args)
        {
            IObservable<int> source = Observable.Range(1, 10);
            IObserver<int> obsvr = Observer.Create<int>(
                x => Console.WriteLine("OnNext: {0}", x),
                ex => Console.WriteLine("OnError: {0}", ex.Message),
                () => Console.WriteLine("OnCompleted"));
            IDisposable subscription = source.Subscribe(obsvr);
            Console.WriteLine("Press ENTER to unsubscribe...");
            Console.ReadLine();
            subscription.Dispose();
       }
    }
}

显示

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 using  System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;

namespace RxConsole
{
    class Program
    {

        static void Main(string[] args)
        {

            //等待10s后开始以2s为时间区间调用
            var source = Observable.Timer(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2))
                                   .Timestamp();
            using (source.Subscribe(x => Console.WriteLine("{0}: {1}", x.Value, x.Timestamp)))
            {
                Console.WriteLine("Press any key to unsubscribe");
                Console.ReadKey();
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();


        }

    }
}

3、待续

本文由分分快三计划发布,转载请注明来源

关键词: 分分快三计划