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


C# ReactiveProperty.Throttle方法代码示例

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


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

示例1: MainViewModel

        public MainViewModel()
        {
            _directoryToMonitor = new DirectoryInfo(Properties.Settings.Default.DirectoryToObserve);
            _fileEndingFilters = Properties.Settings.Default.FileFilters.Split(' ');
            SearchTerm = new ReactiveProperty<string>();
            _episodes = new ObservableCollection<Episode>();
            _allEpisodes = new List<Episode>();

            var loadedEpisodes = from _ in Observable.Interval(TimeSpan.FromSeconds(5)).Merge(Observable.Return(0L))
                              let files = GetFiles(_directoryToMonitor.ToString(), _fileEndingFilters, SearchOption.AllDirectories)
                              select files.Select(file => new Episode(new FileInfo(file))).ToList();

            loadedEpisodes.Subscribe(files =>
                {
                    _allEpisodes = files;
                });

            var searchClickEvents = SearchTerm.Throttle(TimeSpan.FromMilliseconds(100));

            searchClickEvents.ObserveOn(SynchronizationContext.Current).Subscribe(_ =>
                {
                    var episodes = from episode in _allEpisodes
                                   where IsContainedInFilter(episode.File.Name)
                                   select episode;

                    _episodes.Clear();
                    foreach (var episode in episodes)
                        _episodes.Add(episode);
                });
        }
开发者ID:AndreasPresthammer,项目名称:PiratePlayer,代码行数:30,代码来源:MainViewModel.cs

示例2: MainWindowVm

        public MainWindowVm()
        {
            SelectedRepository
                .AddTo(MultipleDisposable);

            Repositories = App.Instance.Repositories
                .ToReadOnlyReactiveCollection(x => new RepositoryVm(x, this))
                .AddTo(MultipleDisposable);

            Title = SelectedRepository
                .Select(x => x == null ? "Anne" : "Anne -- " + x.Path)
                .ToReadOnlyReactiveProperty()
                .AddTo(MultipleDisposable);

            Filter = new ReactiveProperty<string>(string.Empty)
                .AddTo(MultipleDisposable);

            Filter
                .Throttle(TimeSpan.FromMilliseconds(300))
                .Where(_ => SelectedRepository.Value != null)
                .Subscribe(x => SelectedRepository.Value.WordFilter.Value = new WordFilter(x))
                .AddTo(MultipleDisposable);

            SelectedRepository
                .Subscribe(_ => Filter.Value = string.Empty)
                .AddTo(MultipleDisposable);

            SelectedRepository.Value = Repositories.FirstOrDefault();

            Repositories
                .CollectionChangedAsObservable()
                .Where(_ => SelectedRepository.Value == null)
                .Subscribe(_ => SelectedRepository.Value = Repositories.FirstOrDefault())
                .AddTo(MultipleDisposable);

            // 現在のフォーカスを持っているコントロールを表示する
            #if false
            Task.Run(() =>
            {
                while (true)
                {
                    Application.Current.Dispatcher.Invoke(() => Debug.WriteLine(Keyboard.FocusedElement));
                    Thread.Sleep(1000);
                }
            });
            #endif
        }
开发者ID:YoshihiroIto,项目名称:Anne,代码行数:47,代码来源:MainWindowVm.cs


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