system.reactive

Working with Events in F#

£可爱£侵袭症+ 提交于 2019-12-06 04:59:46
问题 I recently asked this question: Replay Recorded Data Stream in F# and combined that code with a subset of the functionality I found here: http://www.mattssoftwareblog.com/?p=271 which combined looks like this: #r "System.Reactive" #r "System.CoreEx" #r "FSharp.PowerPack" #r "WindowsBase" #r "PresentationCore" #r "PresentationFramework" #r "System.Xaml" #r "System.Interactive.dll" open System open System.Linq open System.Collections.Generic open System.Net open System.IO open System.Threading

RX AutoCompleteBox

浪尽此生 提交于 2019-12-06 04:35:18
问题 I'm trying to build an filter control using RX and WPF. So I have a textbox and a listbox. On start up the listbox has 100 contact names and the user can type in a name to filter the list. Question is how can I build up an text stream (key inputs) and then publish. This should be Time sensitive so I guess only after 750milliseconds if a key input hasnt been detected then the filter may be performed. Thanks 回答1: The basic outline would looks like so textbox keydown event converted to an IO

RX: How to process n buffered items from a sequence then wait t seconds before processing the next n items?

僤鯓⒐⒋嵵緔 提交于 2019-12-06 04:35:06
I'm trying to figure out how to process n buffered items from a sequence then wait t seconds before processing the next n items? Here's a crude form of what I'm trying to do, using Thread.Sleep(). I want to avoid Thread.Sleep() and do it properly. static void Main(string[] args) { var t = Observable.Range(0, 100000); var query = t.Buffer(20); query.ObserveOn(NewThreadScheduler.Default) .Subscribe(x => DoStuff(x)); Console.WriteLine("Press ENTER to exit"); Console.ReadLine(); } static void DoStuff(IList<int> list) { Console.WriteLine(DateTime.Now); foreach (var value in list) { Console

How to make delay in calling textchanged event of textbox in wpf

喜欢而已 提交于 2019-12-06 04:28:31
I have custom control inherited from Textbox. I want to make delay in calling textchanged event. Observable.FromEventPattern<TextChangedEventHandler, TextChangedEventArgs>( handler => this.TextChanged += handler, handler => this.TextChanged -= handler ).Throttle(TimeSpan.FromMilliseconds(600)) .Where(e => { var control= e.Sender as TextBox; return control!= null && !string.IsNullOrEmpty(control.Text); }) .Subscribe(x => Control_TextChanged(x.Sender, x.EventArgs)); Problem is it is giving error saying, cannot access Text property as current thread does not have access. Can someone please advice

How to use Observable.FromEvent with static events?

泄露秘密 提交于 2019-12-06 04:22:18
I am trying to use Reactive Extensions to write code to handle an asynchronous call where both the initiating method and the completed event are static. I can't use var languageSetsLoaded = Observable .FromEvent<LoadLanguageSetsCompletedEventArgs>( LanguageManager, "LanguageSetsLoaded") as LanguageManager is a static class rather than an instance, so I tried var languageSetsLoaded = Observable .FromEvent<LoadLanguageSetsCompletedEventArgs>( h => LanguageManager.LanguageSetsLoaded += h, h => LanguageManager.LanguageSetsLoaded -= h ) but that gives a syntax error "Cannot convert lambda

With Reactive Extensions (RX), is it possible to add a “Pause” command?

落花浮王杯 提交于 2019-12-06 03:47:23
问题 I have a class which takes in a stream of events, and pushes out another stream of events. All of the events use Reactive Extensions (RX). The incoming stream of events is pushed from an external source into an IObserver<T> using .OnNext , and the outgoing stream of events is pushed out using IObservable<T> and .Subscribe . I am using Subject<T> to manage this, behind the scenes. I am wondering what techniques there are in RX to pause the output temporarily. This would mean that incoming

How to “reconstruct lines” of data read from SerialPort using Rx

久未见 提交于 2019-12-06 03:36:15
问题 I'm just learning Rx and was trying to implement a "NMEA sentence reader" from a GPS device using SerialPort. The fact that it's GPS data is of lesser importance to the question, so let's just clarify that the NMEA format consists of lines, and a '$' sign represents the start of a new entry, so you get "sentences" that look similar to: $[data for first line goes here] $[data for second line goes here] ... Hooking up the SerialPort's DataReceived event is pretty straightforward: var port = new

How to cancel an observable sequence

♀尐吖头ヾ 提交于 2019-12-06 03:02:25
问题 I have a very simple IObservable<int> that acts as a pulse generator every 500ms: var pulses = Observable.GenerateWithTime(0, i => true, i => i + 1, i => i, i => TimeSpan.FromMilliseconds(500)) And I have a CancellationTokenSource (that is used to cancel other work that is going on simultaneously). How can I use the cancellation token source to cancel my observable sequence? 回答1: If you're using the GenerateWithTime (replaced now with Generate passing in a timespan func overload), you can

Should I use List<IObserver> or simply Action<T> to keep track of an IObservable's subscribers?

我与影子孤独终老i 提交于 2019-12-06 03:02:19
I'm implementing the IObservable<T> interface on some classes. I used Reflector to figure out how this is typically done in Rx . Concerning how an observable keeps track of its subscribers and notifies them via their OnNext method, I stumbled upon code similar to this: private List<Observer<T>> observers; // subscribe a new observer: public IDisposable Subscribe(IObserver<T> observer) { observers.Add(observer); ... } // trigger all observers' OnNext method: ... foreach (IObserver<T> observer in observers) { observer.OnNext(value); } Since all delegates are multi-cast, couldn't this be

Convert IEnumerable<Task<T>> to IObservable<T>

荒凉一梦 提交于 2019-12-06 01:52:29
问题 I'm trying to use the Reactive Extensions (Rx) to buffer an enumeration of Tasks as they complete. Does anyone know if there is a clean built-in way of doing this? The ToObservable extension method will just make an IObservable<Task<T>> , which is not what I want, I want an IObservable<T> , that I can then use Buffer on. Contrived example: //Method designed to be awaitable public static Task<int> makeInt() { return Task.Run(() => 5); } //In practice, however, I don't want to await each