Rx ForkJoin 不适用于自定义事件
我有一些自定义事件参数:
AutoOccurPerformedEventArgs : EventArgs
并且在 2 个不同的位置引发了具有这些事件参数的相同事件,我正在尝试使用反应式扩展来分叉这些事件,然后订阅
var events = new[]
{
Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel1, "AutoOccurActionPerformed"),
Observable.FromEvent<AutoOccurPerformedEventArgs>(viewModel2, "AutoOccurActionPerformed"),
};
events.ForkJoin().Subscribe(op => IsUpdatedByAutoOccur = op.Any(observedItem => observedItem.EventArgs.IsUpdatedByAutoOccur));
订阅中的我的匿名委托永远不会被调用。不会引发任何异常,只是永远不会调用委托。
但是,如果我单独订阅每个事件,而不使用 ForkJoin,则事件会被正确处理(尽管是单独的)
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);
关于为什么 ForkJoin 不起作用的任何想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看有关
ForkJoin
方法的智能感知帮助。尽管有拼写错误,但它说:由于您正在对事件执行
ForkJoin
,因此您永远不会得到结果,因为这些类型的可观察量永远不会完成。您可能想使用
Merge
或CombineLatest
来实现您想要的,但由于您没有描述您的意图,我无法给出更好的建议。Have a look at the intellisense help on the
ForkJoin
method. Despite the spelling error, it says: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
orCombineLatest
to achieve what you want, but since you didn't describe your intent I can't give a better suggestion.