system.reactive

Continue using subscription after exception

橙三吉。 提交于 2019-12-07 03:31:30
I was trying out a "type-to-search" Reactive-Extensions sample which takes a string from a textbox (WPF app if it matters) and does a potentially-lengthy server-side search (simulated in my case with a Thread.Sleep) and displays the result(s) in a listbox. The key features of this particular "module" would be : async search; UI is not frozen while searching throttled; typing fast would not generate a server-side search for each keystroke distinct searching; after searching for "asd" and having the result(s) displayed typing fast [backspace], d (i.e. deleting the last character and retyping it

IObservable ambiguous reference error

断了今生、忘了曾经 提交于 2019-12-07 03:13:22
问题 I'm using Reactive extensions in my WPF application. And while using it I'm getting below ambiguous reference error. The type 'System.IObservable<T>' exists in both 'mscorlib.dll' and 'System.Reactive.dll' I tried with fully qualified name also and tried this url as well, but didn't get any luck. I'm using .NET 4.0 version of Reactive Extensions. My Code: using System; // mscorlib.dll using Rx = System.Reactive; public Rx.IObservable<int> BytesReceived { get { return _bytesReceivedSubj; } } /

Track the (number of) observers in an Observable?

99封情书 提交于 2019-12-07 01:13:46
问题 I have an observable which represents a stream of stock prices. If there are no observers on my observable sequence I'd like to be able to disconnect from the remote server that is supplying the stream of prices, but I don't want to do that until every observer has called Dispose(). Then in a similar fashion, when the first person calls Subscribe I'd like to reconnect to the remote server. Is there a way to figure out how many observers have called subscribe on an observable? Or perhaps a way

Does my “zipLatest” operator already exist?

三世轮回 提交于 2019-12-06 23:52:14
问题 quick question about an operator I've written for myself. Please excuse my poor-man's marble diagrams: zip aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ --a1----b2--c3--------d4--e5---- combineLatest aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ --a1b1--c2--d3--e3--f3f4--f5--g5 zipLatest aa--bb--cc--dd--ee--ff--------gg --11----22--33--------44--55---- ================================ -

“Exclusive” and “Default” Subscription Modes in Rx

旧城冷巷雨未停 提交于 2019-12-06 15:57:14
I have an observable sequence of event objects and a number of observers handling specific types of events. I need to accomplish the following scenarios: Some event types need to be handled by the first observer matching a condition (e.g. observable.SubscribeExclusively(x=>{}) and become "unobservable" to the others. If there are no subscriptions, set some default handler (e.g. observable.SubscribeIfNoSubscriptions(x=>{})) so that no items get lost (this handler may for example save the item to a database so that it is processed later). Is there a way to handle these cases with Rx? I'm not

Combining latest from an observable of observables

你离开我真会死。 提交于 2019-12-06 15:42:44
Suppose I have a set of URIs that I am monitoring for availability. Each URI is either "up" or "down", and new URIs to monitor may be added to the system at any time: public enum ConnectionStatus { Up, Down } public class WebsiteStatus { public string Uri { get; set; } public ConnectionStatus Status { get; set; } } public class Program { static void Main(string[] args) { var statusStream = new Subject<WebsiteStatus>(); Test(statusStream); Console.WriteLine("Done"); Console.ReadKey(); } private static void Test(IObservable<WebsiteStatus> statusStream) { } } Now suppose in Test() I want to

Observable.Retry doesn't work as expected

喜你入骨 提交于 2019-12-06 15:05:17
I have a sequence of numbers that are processed using an async method. I'm simulating a remote service call that may fail . In case of failure, I would like to retry until the call successes. The problem is that with the code I'm trying, every time an exception is thrown in the async method, the sequence seems to hang forever . You can test it with this simple code snippet (it's tested in LINQPad) Random rnd = new Random(); void Main() { var numbers = Enumerable.Range(1, 10).ToObservable(); var processed = numbers.SelectMany(n => Process(n).ToObservable().Retry()); processed.Subscribe( f =>

How to create an Rx (RxJS) stream that can be switched between single-item and batch-mode?

試著忘記壹切 提交于 2019-12-06 14:15:31
问题 I have an Rx stream that is an outgoing change feed from a particular component. Occasionally I want to be able to enter a batch mode on the stream so that items passed to onNext accumulate and are passed on only when the batch mode is exited. Normally I'll pass single items through the stream: stream.onNext(1); stream.onNext(2); There is a 1-to-1 mapping between the items passed to onNext and the items received in the subscribe , so the previous snippet results in two calls to subscribe with

Observable.FromAsyncPattern with UDPClient.EndReceive and ref remote endpoint Parameter

与世无争的帅哥 提交于 2019-12-06 13:31:12
I'm learning about Reactive extensions and trying to re-factor some of my code. UDPClient.EndReceive takes a ref IPEndPoint parameter, so I currently have this working: UdpClient receiverUDP = new UdpClient(); receiverUDP.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); receiverUDP.EnableBroadcast = true; receiverUDP.Client.ExclusiveAddressUse = false; receiverUDP.Client.Bind(new IPEndPoint(IPAddress.Any, 1234)); IPEndPoint ep = null; var async = Observable.FromAsyncPattern<byte[]>(receiverUDP.BeginReceive, (i) => receiverUDP.EndReceive(i, ref ep)); var

Using Rx over events on a WPF UserControl, why does the control receive a mousedown and mousemove when the window is maximized?

喜你入骨 提交于 2019-12-06 13:09:48
This one's got me a bit baffled. I've written some extension methods on UIElement to provide Observables on some of the mouse events. Here are the relevant ones: public static IObservable<EventPattern<MouseEventArgs>> ObserveMouseLeftButtonDown(this UIElement element) { return Observable.FromEventPattern<MouseEventArgs>(element, "MouseLeftButtonDown"); } public static IObservable<EventPattern<MouseEventArgs>> ObserveMouseMove(this UIElement element) { return Observable.FromEventPattern<MouseEventArgs>(element, "MouseMove"); } So far, so mind-numbingly simple. Then I create a composite event to