开发者

Rx ForkJoin is not working with custom event

I have some custom event args:

AutoOccurPerformedEventArgs : EventArgs

and the same event with these event args is raised in 2 seperate locations I'm trying to use the Reactive Extensions to forkjoin these and then subscribe

var events = new[]
                        {
                            Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel1, "AutoOccurActionPerformed"),
                            Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel2, "AutoOccurActionPerformed"),
                        };
events.ForkJo开发者_如何转开发in().Subscribe(op => IsUpdatedByAutoOccur = op.Any(observedItem => observedItem.EventArgs.IsUpdatedByAutoOccur));

My anonymous delegate in the subscribe never gets called. No exceptions are raised, the delegate just never gets invoked.

However, if I subscribe to each event individually, without ForkJoin, the events are handled correctly (although seperately)

Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel1, "AutoOccurActionPerformed")
                .Subscribe(o => IsUpdatedByAutoOccur = o.EventArgs.IsUpdatedByAutoOccur ? true : IsUpdatedByAutoOccur);

Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel2, "AutoOccurActionPerformed")
                .Subscribe(o => IsUpdatedByAutoOccur = o.EventArgs.IsUpdatedByAutoOccur ? true : IsUpdatedByAutoOccur);

Any ideas as to why ForkJoin is not working?


Have a look at the intellisense help on the ForkJoin method. Despite the spelling error, it says:

Runs two observable sequences in parallel and combines their last elemenets.

Since you are doing a ForkJoin over events you will never get a result because these type of observables never complete.

You possibly want to use Merge or CombineLatest to achieve what you want, but since you didn't describe your intent I can't give a better suggestion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜