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


C# IObservable.ObserveOn方法代码示例

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


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

示例1: ExerciseViewModel

        public ExerciseViewModel(ISchedulerService schedulerService, Exercise model, IObservable<ExecutionContext> executionContext)
        {
            schedulerService.AssertNotNull(nameof(schedulerService));
            model.AssertNotNull(nameof(model));
            executionContext.AssertNotNull(nameof(executionContext));

            this.disposables = new CompositeDisposable();
            this.model = model;

            executionContext
                .ObserveOn(schedulerService.MainScheduler)
                .Subscribe(x => this.ExecutionContext = x)
                .AddTo(this.disposables);

            Observable
                .CombineLatest(
                    this
                        .WhenAnyValue(x => x.ExecutionContext)
                        .Select(ec => ec == null ? Observable.Never<TimeSpan>() : ec.WhenAnyValue(x => x.SkipAhead))
                        .Switch(),
                    this
                        .WhenAnyValue(x => x.ExecutionContext)
                        .Select(ec => ec == null ? Observable.Never<Exercise>() : ec.WhenAnyValue(x => x.CurrentExercise))
                        .Switch(),
                    (skip, current) => skip == TimeSpan.Zero && current == this.model)
                .ObserveOn(schedulerService.MainScheduler)
                .Subscribe(x => this.IsActive = x)
                .AddTo(this.disposables);

            this
                .WhenAnyValue(x => x.ExecutionContext)
                .Select(
                    ec =>
                        ec == null
                            ? Observable.Return(TimeSpan.Zero)
                            : ec
                                .WhenAnyValue(x => x.CurrentExerciseProgress)
                                .Where(_ => ec.CurrentExercise == this.model)
                                .StartWith(TimeSpan.Zero))
                .Switch()
                .ObserveOn(schedulerService.MainScheduler)
                .Subscribe(x => this.ProgressTimeSpan = x)
                .AddTo(this.disposables);

            this
                .WhenAny(
                    x => x.Duration,
                    x => x.ProgressTimeSpan,
                    (duration, progressTimeSpan) => progressTimeSpan.Value.TotalMilliseconds / duration.Value.TotalMilliseconds)
                .Select(progressRatio => double.IsNaN(progressRatio) || double.IsInfinity(progressRatio) ? 0d : progressRatio)
                .Select(progressRatio => Math.Min(1d, progressRatio))
                .Select(progressRatio => Math.Max(0d, progressRatio))
                .ObserveOn(schedulerService.MainScheduler)
                .Subscribe(x => this.Progress = x)
                .AddTo(this.disposables);
        }
开发者ID:reactiveui-forks,项目名称:WorkoutWotch,代码行数:56,代码来源:ExerciseViewModel.cs

示例2: PegCompiler

        public PegCompiler(IObservable<Grammar> grammars)
        {
            var compileResults = grammars
                .ObserveOn(Scheduler.Default)
                .Select(r => r == null ? new Compiler.CompileResult(r) : Compiler.PegCompiler.Compile(r))
                .Publish()
                .RefCount();

            this.Codes = compileResults.Select(r => r.Code);
            this.Errors = compileResults.Select(r => r.Errors.ToList().AsReadOnly());
        }
开发者ID:otac0n,项目名称:Pegasus,代码行数:11,代码来源:PegCompiler.cs

示例3: CsCompiler

        public CsCompiler(IObservable<Tuple<string, Grammar>> codeAndGrammar)
        {
            var csCompilerResults = codeAndGrammar
                .ObserveOn(Scheduler.Default)
                .Select(p => Compile(p.Item1, p.Item2))
                .Publish()
                .RefCount();

            this.Parsers = csCompilerResults.Select(r => r.Parser);
            this.Errors = csCompilerResults.Select(r => r.Errors);
        }
开发者ID:otac0n,项目名称:Pegasus,代码行数:11,代码来源:CsCompiler.cs

示例4: PegParser

        public PegParser(IObservable<string> subjects)
        {
            var internalParseResults = subjects
                .ObserveOn(Scheduler.Default)
                .Select(Parse)
                .Publish()
                .RefCount();

            this.Grammars = internalParseResults.Select(g => g.Grammar);
            this.Errors = internalParseResults.Select(g => g.Errors.AsReadOnly());
            this.LexicalElements = internalParseResults.Select(g => g.LexicalElements);
        }
开发者ID:otac0n,项目名称:Pegasus,代码行数:12,代码来源:PegParser.cs

示例5: MessagesView

        public MessagesView(IObservable<Message> messagesObservable, bool showSendArea = true) 
        {
            _showSendArea = showSendArea;
            _items = new ObservableCollection<Message>();

            InitView();

            _sendButton.Clicked += async (sender, args) => await SendClicked();
            _textToSendEntry.Completed += async (sender, args) => await SendClicked();

            messagesObservable
                .ObserveOn(SynchronizationContext.Current)
                .Subscribe(m =>  _items.Add(m));
        }
开发者ID:Elecstrap,项目名称:sockets-for-pcl,代码行数:14,代码来源:MessagesView.cs

示例6: Account

        public Account(
            string login,
            bool isUser,
            bool isEnterprise,
            int ownedPrivateRepositoryCount,
            long privateRepositoryInPlanCount,
            IObservable<BitmapSource> bitmapSource)
        {
            Login = login;
            IsUser = isUser;
            IsEnterprise = isEnterprise;
            OwnedPrivateRepos = ownedPrivateRepositoryCount;
            PrivateReposInPlan = privateRepositoryInPlanCount;
            IsOnFreePlan = privateRepositoryInPlanCount == 0;
            HasMaximumPrivateRepositories = OwnedPrivateRepos >= PrivateReposInPlan;

            avatar = bitmapSource.ObserveOn(RxApp.MainThreadScheduler)
                .ToProperty(this, a => a.Avatar);
        }
开发者ID:chris134pravin,项目名称:VisualStudio,代码行数:19,代码来源:Account.cs

示例7: Aggregate

 private void Aggregate(IObservable<LogEvent> events)
 {
     Guid g = Guid.NewGuid();
     Console.WriteLine(g + " opened at "+ DateTime.Now);
     List<LogEvent> allEvents = new List<LogEvent>();
     events.ObserveOn(TaskPoolScheduler.Default).Subscribe(
         evt => allEvents.Add(evt),
         () =>
     {
         Console.WriteLine(g + " closed at " + DateTime.Now);
         var gr = GroupCounters(allEvents);
         _aggregationCompleteSubject.OnNext(gr.Select(gouppedValues =>
         {
             AggregatedValue result =
                 new AggregatedValue(
                     gouppedValues.Key,
                     _aggregationOperation.Do(
                         gouppedValues.ToList()));
             Console.WriteLine(DateTime.Now + " Aggregated on thread #" + Thread.CurrentThread.ManagedThreadId);
             return result;
         }).ToList());
         Console.WriteLine(g + " Finished on thread #" + Thread.CurrentThread.ManagedThreadId+"\r\n"+string.Join("\r\n",allEvents));
     });
 }
开发者ID:demonix,项目名称:iPoint.ServiceStatistics,代码行数:24,代码来源:Aggregator.cs

示例8: GetOEmbeds

        /// <summary>
        /// Gets multiple oEmbeds
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="urls">The urls.</param>
        /// <param name="providerFilter">The provider filter.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static IObservable<Result> GetOEmbeds(this Client client, IObservable<Uri> urls, Func<Provider, bool> providerFilter, RequestOptions options)
        {
            if (urls == null)
                throw new ArgumentNullException("urls");

            if (options == null)
                throw new ArgumentNullException("options");

            var requests = urls
                .ObserveOn(NewThreadScheduler.Default)
                .Select(u => u.MakeUrlRequests(client))
                .WhereProvider(providerFilter);

            var redirector = new RequestObserver(client, options);

            requests.Subscribe(redirector);

            return redirector.Output;
        }
开发者ID:powerinbox,项目名称:embedly-dotnet,代码行数:27,代码来源:Extensions.cs

示例9: Presenter

 public Presenter(IObservable<string[]> models, IScheduler scheduler)
 {
     TableViewModel = models.ObserveOn (scheduler);
 }
开发者ID:petmac,项目名称:xamarin-reactive-test,代码行数:4,代码来源:Presenter.cs

示例10: BeginAggregation

 public void BeginAggregation(IObservable<IList<LogEventArgs>> observableEvents)
 {
     UnsubscriptionToken = observableEvents.ObserveOn(Scheduler.Default).Subscribe(AggregationAction);
 }
开发者ID:demonix,项目名称:iPoint.ServiceStatistics,代码行数:4,代码来源:CounterAggregator.cs

示例11: MouseHover

        void MouseHover()
        {
            // Here create an event stream called mouseGeosWithMouseWheelNulls, which consists of the MouseGeo event stream, 
            // merged with another stream that produces a null every time the mouse wheel is moved
            // Here create an event stream called MouseHoverGeo, which consists of mouseGeosWithMouseWheelNulls events 
            // filtered to only give us an event after 300 ms of inactivity with duplicate events and null events removed
            MouseHoverGeo = MouseGeo.Throttle(TimeSpan.FromMilliseconds(300))
                .Merge(Observable.FromEventPattern<MouseWheelEventArgs>(_wpfMap, "MouseWheel").Select(e => (Geo)null))
                .Merge(MouseGeo.Select(e => (Geo)null))
                .DistinctUntilChanged();
            //MouseHoverGeo.ObserveOn(TaskPoolScheduler.Default).Subscribe(g => Debug.WriteLine(string.Format("{0:HH:mm:ss:fff} MouseHoverGeo is now {1}", DateTime.Now, g)));

#if false
    // Observe the MouseHoveGeo event stream on the TaskPool
            _mouseHover = MouseHoverGeo.ObserveOn(TaskPoolScheduler.Default)
                .Subscribe(g =>
                {
                    var pointShape = new PointShape(g.Longitude, g.Latitude);
                    foreach (var activeLayerOverlay in _wpfMap.Overlays.OfType<ActiveLayerOverlay>().ToList())
                    {
                        foreach (var featureLayer in activeLayerOverlay.Layers.OfType<FeatureLayer>().ToList())
                        {
                            try
                            {
                                featureLayer.Open();
                                var featureCollection = featureLayer.QueryTools.GetFeaturesContaining(pointShape, ReturningColumnsType.NoColumns);
                                if (featureCollection.Count == 0) continue;
                                activeLayerOverlay.MouseIsHovering.OnNext(true);
                                _hoveringOverlays.Add(activeLayerOverlay);
                            }
                            finally
                            {
                                if (featureLayer.IsOpen) featureLayer.Close();
                            }
                        }
                    }
                });
            mouseGeoWithMouseWheelNull.ObserveOn(TaskPoolScheduler.Default)
                .Subscribe(g =>
                {
                    while (!_hoveringOverlays.IsEmpty)
                    {
                        ActiveLayerOverlay overlay;
                        if (_hoveringOverlays.TryTake(out overlay)) overlay.MouseIsHovering.OnNext(false);
                    }
                });
#endif
        }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:48,代码来源:MapViewModel.cs

示例12: StartTracking

 public void StartTracking(IObservable<PlotData> data)
 {
     var disposable = data.ObserveOn(this).Subscribe(DisplayPlotData);
 }
开发者ID:Shinbuev,项目名称:Orthopedy,代码行数:4,代码来源:PlotForm.cs


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