system.reactive

Update collection based on timer throws 'Collection was modified; enumeration operation may not execute.'

喜欢而已 提交于 2019-12-13 03:55:52
问题 I'm using Reactive Extensions and ReactiveUI to update a collection of Process objects periodically. When a checkbox is checked the property Processes, which is bound to a DataGrid, is filled and a timer is set to update every 200ms all processes. Processes that have exited are removed. The Collection was modified; enumeration operation may not execute. exception is sometimes thrown when doing a foreach. I don't understand, because I am not removing or adding objects to the collection when

Reactive: Refresh AccessToken using observables

余生颓废 提交于 2019-12-13 03:53:29
问题 I don't quite figure out how to adapt this approach in order to generate dynamic timer observables. Concretly, I've two methods: GetAccessToken() RefreshAccessToken() Both returns a OAuth2AccessTokenResponse : public class OAuth2AccessTokenResponse { private string tokenType; private string accessToken; private int expiresIn; private string refreshToken; private int refreshtokenExpiresIn; } So, I need to refresh the current accesstoken before expiresIn property value in seconds elapses. I've

Dynamic timer observable

风流意气都作罢 提交于 2019-12-13 03:47:17
问题 I'm facing with an issue related with how to create a dynamic "timer" observable. Slightly I mean, I need to perform a function and according the value it returns (integer representing the number of seconds) I need to call the same function after these seconds have elapsed. So, I guess I need to re-schedule the observable according this another new value seconds. I've tried to find something overthere but I',ve not been able to figure out what do I need to do. Any ideas? 回答1: Use Observable

Polling a website using Rx

北城余情 提交于 2019-12-13 03:22:35
问题 just trying to get my head around Rx I am using Rx to poll a website every 2 seconds var results = new List<MyDTO>(); var cx = new WebserviceAPI( ... ); var callback = cx.GetDataAsync().Subscribe(rs => { results.AddRange(rs); }); var poller = Observable.Interval(TimeSpan.FromSeconds(2)).Subscribe( _ => { cx.StartGetDataAsync(); }); (The webservice API exposes a getItemsAsync/getItemsCompleted event handler type mechanism from which I am creating an observable). When the web site returns, I am

ReactiveUI 5 instant search

陌路散爱 提交于 2019-12-13 03:03:31
问题 Following my earlier question about Reactive Extensions Instant Search for WPF/MVVM, wherein... I would like to implement a TextBox where, as you type, results appear instantly in another ListBox ...I found that this problem had originally been addressed by ReactiveUI and there was a relatively straightforward solution posted in the ReactiveUI blog and documentation. Fast forward to ReactiveUI 5, and the API has been changed, and the old examples don't work any more. ReactiveAsyncCommand has

Whats a good way to run periodic tasks in c# using Rx with a single concurrent execution restriction?

微笑、不失礼 提交于 2019-12-13 01:45:54
问题 I want to run periodic tasks in with a restriction that at most only one execution of a method is running at any given time. I was experimenting with Rx, but I am not sure how to impose at most once concurrency restriction. var timer = Observable.Interval(TimeSpan.FromMilliseconds(100)); timer.Subscribe(tick => DoSomething()); Additionally, if a task is still running, I want the subsequent schedule to elapse. i.e I don't want the tasks to queue up and cause problems. I have 2 such tasks to

new data to observable with each method invocation

偶尔善良 提交于 2019-12-13 01:40:14
问题 this may be really simple to those in the know-how, but how can i directly provide new data to a given observable, whenever a method of mine is invoked? IObservable<int> _myObservable; void ThingsCallMe(int someImportantNumber) { // Current pseudo-code seeking to be replaced with something that would compile? _myObservable.Add(someImportantNumber); } void ISpyOnThings() { _myObservable.Subscribe( i => Console.WriteLine("stole your number " + i.ToString())); } i also dont know what kind of

Is Rx extensions suitable for reading a file and store to database

大憨熊 提交于 2019-12-13 01:16:08
问题 I have a really long Excel file wich I read using EPPlus. For each line I test if it meets certain criteria and if so I add the line (an object representing the line) to a collection. When the file is read, I store those objects to the database. Would it be possible to do both things at the same time? My idea is to have a collection of objects that somehow would be consumed by thread that would save the objects to the DB. At the same time the excel reader method would populate the collection.

Ignore incoming stream updates if last callback hasn't finished yet

被刻印的时光 ゝ 提交于 2019-12-13 00:41:03
问题 I have code similar to this. IPruduceDemUpdates.Subscribe(update => DoUpdate(update)); But what I want to do is something like that. IPruduceDemUpdates.Subscribe(update => if(NoDoUpadteIsRunning) DoUpdate(update)); So it ignores incoming updates, if the update method is already running. In addition, it should always execute the last update. No matter if it is the last update of the stream or the last for a period of time. Here an example timeline Update 1 starts Update 2 is ignored Update 3

Turning a method call into an observable event, good idea?

余生长醉 提交于 2019-12-13 00:25:21
问题 I'm learning how to incorporate IObservable into my code. Below are two different approaches for a simple class that prints out the most recent word from an IObservable<string> . Which is the cleaner approach? I don't like WordPrinterWithCache because it introduces additional state (the _lastWord ) variable and the interesting code is now scattered throughout the class. I prefer WordPrinterWithExtraSubject because the interesting code is localized to the constructor. But mostly it seems more