Reputation: 475
Why does a rx observing an event missed? The event is not handled at the time it occurs so the inner state of the object is not updated and causes problems in the following events received. Can it be due to 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);
});
}
I can see the event is received but the code above is blocking!
Upvotes: 1
Views: 358
Reputation: 12700
Your code sample looks fine to me, although the use of the Take(1)
operator will result in only ever catching the first event at which point the stream will complete and you will not receive any additional notifications. Is it your intention to only listen for a single event notification?
Perhaps removing Take(1) will give you the correct behaviour?
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);
});
}
Upvotes: 1