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


C# BehaviorSubject.Throttle方法代码示例

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


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

示例1: ObservableThreadsWithThrottleOnCompute

 public void ObservableThreadsWithThrottleOnCompute()
 {
     Console.WriteLine("Starting Thread " + Thread.CurrentThread.ManagedThreadId);
     BehaviorSubject<int> s1 = new BehaviorSubject<int>(2);
     BehaviorSubject<int> s2 = new BehaviorSubject<int>(3);
     BehaviorSubject<int> sum = new BehaviorSubject<int>(5);
     List<int> computeThreads = new List<int>();
     List<int> receiveThreads = new List<int>();
     IScheduler computeScheduler = new EventLoopScheduler();
     IObservable<int> sumObservable = s1.Throttle(TimeSpan.FromMilliseconds(100), computeScheduler).ObserveOn(computeScheduler).CombineLatest(s2.Throttle(TimeSpan.FromMilliseconds(100), computeScheduler).ObserveOn(computeScheduler), (first, second) =>
         {
             Console.WriteLine("Computing value " + first + " + " + second + " = " + (first + second) + " on Thread " + Thread.CurrentThread.ManagedThreadId + ".");
             computeThreads.Add(Thread.CurrentThread.ManagedThreadId);
             return first + second;
         });
     sumObservable.Subscribe(sum.OnNext);
     sum.ObserveOn(new EventLoopScheduler()).Subscribe(v =>
         {
             Console.WriteLine("Received value " + v + " on Thread " + Thread.CurrentThread.ManagedThreadId + ".");
             receiveThreads.Add(Thread.CurrentThread.ManagedThreadId);
         });
     Thread.Sleep(150);
     s2.OnNext(1);
     Thread.Sleep(50);
     s1.OnNext(4);
     Thread.Sleep(150);
     s2.OnNext(4);
     Thread.Sleep(250);
     s1.OnNext(1);
     Thread.Sleep(150);
     foreach (KeyValuePair<int, int> p in
         computeThreads.GroupBy(v => v).Select(g => new KeyValuePair<int, int>(g.Key, g.Count())))
     {
         Console.WriteLine(p.Value + " computes on Thread " + p.Key);
     }
     foreach (KeyValuePair<int, int> p in
         receiveThreads.GroupBy(v => v).Select(g => new KeyValuePair<int, int>(g.Key, g.Count())))
     {
         Console.WriteLine(p.Value + " receives on Thread " + p.Key);
     }
 }
开发者ID:jam40jeff,项目名称:RxMvvm,代码行数:41,代码来源:Sandbox.cs


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