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.ForkJoin().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
ForkJoinmethod. Despite the spelling error, it says:Since you are doing a
ForkJoinover events you will never get a result because these type of observables never complete.You possibly want to use
MergeorCombineLatestto achieve what you want, but since you didn’t describe your intent I can’t give a better suggestion.