繁体   English   中英

反应性扩展(Rx)丢失事件

[英]Reactive Extensions (Rx) Misses event

为什么接收事件的RX错过了? 事件发生时未对其进行处理,因此该对象的内部状态未更新,并在接收到的以下事件中引起了问题。 可能是由于ObserveOn NewThread吗?

private void UpdateList(Client client)
{
    var listUpdateReceive = Observable
        .FromEvent<ListEventArgs>(ev => client.ListUpdateReceive += ev, ev => client.ListUpdateReceive -= ev);

    listUpdateReceive.Take(1)
        .Subscribe(r =>
                       {
                           TraceInformation("List is updated.");

                           OnListUpdateReceived(r.Sender, r.EventArgs);
                       });
}

我可以看到事件已收到,但是上面的代码被阻止了!

我的代码示例看起来不错,尽管使用Take(1)运算符只会导致仅捕获第一个事件,此时流将完成,并且您将不会收到任何其他通知。 您是否打算只听一个事件通知?

也许删除Take(1)将为您提供正确的行为?

private void UpdateList(Client client)
{
    var listUpdateReceive = Observable
        .FromEvent<ListEventArgs>(ev => client.ListUpdateReceive += ev, ev => client.ListUpdateReceive -= ev);

    listUpdateReceive.Subscribe(r =>
        {
           TraceInformation("List is updated.");

           OnListUpdateReceived(r.Sender, r.EventArgs);
        });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM