Help migrating code from earliar version of Rx to new
-
2012年4月11日 12:10
Dear friends,
I am a novice with Rx and I found this code from a silverlightpluscrm book and I tried to use it but its built on the earliar version of Rx with CoreEx assemblies and Observer dll.
Observable.FromEvent<LoadCompletedEventArgs>(collection, "LoadCompleted").Subscribe(loadcompleted =>
{
observer.OnNext(loadcompleted.EventArgs);
});I tried to migrate it using this code and it didn't show errors and compiles but doesn't work.
Observable.FromEvent<EventHandler<LoadCompletedEventArgs>, LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(loadcompleted =>
{
observer.OnNext(loadcompleted);
});I don't know how I could collect the EventArgs as before. I am sorry if my question is silly.
ys,
Sebastian
全部回复
-
2012年4月11日 16:50
Hi Sebastian,
Try Observable.FromEventPattern instead:
Observable.FromEventPattern<LoadCompletedEventArgs>( c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c) .Subscribe(observer.OnNext);
- Dave
http://davesexton.com/blog
-
2012年4月11日 16:53
Hi Sebastian,
Though I suspect that something else may be wrong if your solution doesn't work. If my solution doesn't work either then try placing a breakpoint in Subscribe to make sure that observer.OnNext is being called.
- Dave
http://davesexton.com/blog
-
2012年4月13日 7:24
Hi Dave,
Thanks a lot for your warm and quick response ... I tried to use the code yesterday and tried to play around ... but it is displaying this error. I am very new to Rx. I am not sure how all this works and am presently just blindly playing around.
argument: can be converted from "Method group" in "System.IObserver < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs >
the best match for the overloaded System.IObservable < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs > >.Subscribe (System.IObserver < System.Reactive.EventPattern < System.Data.Services.Client.LoadCompletedEventArgs > >) method has some invalid arguments.
as translated from bingtranslator from German.
ys,
Sebastian
-
2012年4月13日 7:51
Hi Sebastian,
Please post your code that calls Subscribe so that we can see what the compiler is complaining about.
- Dave
- 已编辑 Dave Sexton 2012年4月13日 7:52 Correction: Subscribe
-
2012年4月13日 7:54
Hi Sebastian,
The problem is probably that the method you're passing to Subscribe doesn't accept the correct parameter type. As I mentioned previously, please post some code so that we can see what you're doing.
- Dave
http://davesexton.com/blog
-
2012年4月13日 8:58
public static IObservable<LoadCompletedEventArgs> RxRunQuery<CollectionType>(this DataServiceCollection<CollectionType> collection, IQueryable<CollectionType> query) { return Observable.Create<LoadCompletedEventArgs>(observer => { //Observable.FromEventPattern<LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(observer.OnNext); Observable.FromEvent<EventHandler<LoadCompletedEventArgs>, LoadCompletedEventArgs>(c => collection.LoadCompleted += c, c => collection.LoadCompleted -= c).Subscribe(loadcompleted => { observer.OnNext(loadcompleted); }); collection.LoadAsync(query); return () => { }; }); } public static iobservable<bool> loadallpages<collectiontype>(this dataservicecollection<collectiontype> collection, iqueryable<collectiontype> query) { return observable.create<bool>(observer => { observable.fromevent<loadcompletedeventargs>(collection, "loadcompleted").subscribe(loadcompleted => { if (collection.continuation != null) collection.loadnextpartialsetasync(); else observer.onnext(true); }); collection.loadasync(query); return () => { }; }); } -
2012年4月13日 20:23
Hi Sebastian,
I think the problem is with the call to Subscribe. I used the short-hand syntax in my example but I didn't realize that the type of the data changed. You'll have to change this:
.Subscribe(observer.OnNext)
to this:
.Subscribe(e => observer.OnNext(e.EventArgs))
- Dave
http://davesexton.com/blog
- 已标记为答案 sebastian.mayer.67 2012年5月7日 13:59
-
2012年5月7日 14:20
There are no errors now.
Thanks a lot Dave for you support. I am ashamed for this delayed reply. I am very grateful for you support. I wish you all the best. I will contribute to this forum once I become capable.

