system.reactive

Reactive Extensions (Rx) + MVVM =?

只愿长相守 提交于 2019-12-18 10:01:46
问题 One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new 'event' representing deltas during mouse drag: var mouseMoves = from mm in mainCanvas.GetMouseMove() let location = mm.EventArgs.GetPosition(mainCanvas) select new { location.X, location.Y}; var mouseDiffs = mouseMoves .Skip(1) .Zip(mouseMoves, (l, r) => new {X1 = l.X, Y1 = l.Y, X2 = r.X, Y2 = r.Y}); var mouseDrag = from _ in mainCanvas.GetMouseLeftButtonDown()

Limiting concurrent requests using Rx and SelectMany

大憨熊 提交于 2019-12-18 09:03:13
问题 I have a list of URLs of pages I want to download concurrently using HttpClient . The list of URLs can be large (100 or more!) I have currently have this code: var urls = new List<string> { @"http:\\www.amazon.com", @"http:\\www.bing.com", @"http:\\www.facebook.com", @"http:\\www.twitter.com", @"http:\\www.google.com" }; var client = new HttpClient(); var contents = urls .ToObservable() .SelectMany(uri => client.GetStringAsync(new Uri(uri, UriKind.Absolute))); contents.Subscribe(Console

Using Rx Framework for async calls using the void AsyncMethod(Action<T> callback) pattern

为君一笑 提交于 2019-12-18 07:09:27
问题 I've seen tons of examples on how to use the Observable.FromAsyncPattern() in the Rx Framework to simplify Async calls, but I'm using an interface that doesn't use the standard Async pattern of IAsyncResult BeginXXX/EndXXX(IAsyncResult), so this doesn't work for me. The library I'm working with exposes async functions with a callback patter: void GetAllObjects(Action<List<Object>> callback) In an ideal world I'd like to turn this: var isLoadingUsers = true; var isLoadingSystems = true; var

Why might System.Threading.dll be missing from Windows\Assembly?

﹥>﹥吖頭↗ 提交于 2019-12-18 05:56:18
问题 I've various versions of the .NET Framework (versions 1.1 thru 4.0) installed on a remote machine running XP Professional. I've installed Reactive Extension too for good measure. I also have an application which works on my machine because it references System.Threading found here: C:\Program Files\Microsoft Reactive Extensions\redist\desktopV2\System.Threading.dll I have two versions of the DLL in the GAC also. Two questions: i) Why did Visual Studio decide that this is the version (instance

reactive extensions sliding time window

[亡魂溺海] 提交于 2019-12-18 05:04:32
问题 I have a sequence of stock ticks coming in and I want to take all the data in the last hour and do some processing on it. I am trying to achieve this with reactive extensions 2.0. I read on another post to use Interval but i think that is deprecated. 回答1: Would this extension method solve your problem? public static IObservable<T[]> RollingBuffer<T>( this IObservable<T> @this, TimeSpan buffering) { return Observable.Create<T[]>(o => { var list = new LinkedList<Timestamped<T>>(); return @this

Observable from chained Tasks

空扰寡人 提交于 2019-12-18 04:24:14
问题 I'm trying to create an Observable where each item is produced via an asynchronous task. The next item should be produced via an async call on the result of the previous item (co-recursion). In "Generate" parlance this would look something like this - except that Generate does not support async (nor does it support the delegate on the initial state. var ob = Observable.Generate( async () => await ProduceFirst(), // Task<T> ProduceFirst() prev => Continue(prev) // bool Continue(T); async prev

How to get an IObservable back from Web API

拟墨画扇 提交于 2019-12-18 04:10:51
问题 I have a simple Web API which returns an Iobservable. I am using HttpClient to get the Observable so that I can subscribe to it. My problem is the returned Iobservable on subscription sends out an 'empty' result. SERVER public IObservable<DataItem> GetDataItems() { return Observable.Generate(0, i => i < 10, i => i + 1, i => new DataItem { Id = i, Name = String.Format("Storage{0}",i) }); } CLIENT public IObservable<DataItem> GetDataItems() { using (HttpClient apiClient = new HttpClient()) {

Rx back off and retry

做~自己de王妃 提交于 2019-12-18 04:09:31
问题 This is based on the code presented in this SO : Write an Rx "RetryAfter" extension method I am using the code by Markus Olsson (evaluation only at the moment), and before anyone asks I have tried to get hold of Markus on Github, but that is blocked where I work, so I felt the only thing I could do was ask here at SO. Sorry about that, if this sits badly with any one. So I am using the following code, in a small demo which is this: class Attempt1 { private static bool shouldThrow = true;

How do I implement polling using Observables?

血红的双手。 提交于 2019-12-18 03:35:11
问题 I have a parametrized rest call that should be executed every five seconds with different params: Observable<TResult> restCall = api.method1(param1); I need to create an Observable<TResult> which will poll the restCall every 5 seconds with different values for param1. If the api call fails I need to get an error and make the next call in 5 seconds. The interval between calls should be measured only when restCall is finished (success/error). I'm currently using RxJava, but a .NET example would

Reactive Extensions: Concurrency within the subscriber

让人想犯罪 __ 提交于 2019-12-17 22:41:10
问题 I'm trying to wrap my head around Reactive Extensions' support for concurrency and am having a hard time getting the results I'm after. So I may not get it just yet . I have a source that emits data into the stream faster than the subscriber can consume it. I'd prefer to configure the stream such that another thread is used to invoke the subscriber for each new item from the stream, so that the subscriber has multiple threads running through it concurrently. I am able to ensure the thread