Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Observable.FromEventPattern rather than Observable.FromEvent?

We've got a client calling off to a TIBCO EMS queue and are wiring up the events like this:

var msgConsumer = _session.CreateConsumer(responseQueue); var response = Observable.FromEvent<EMSMessageHandler,EMSMessageEventArgs>             (h => msgConsumer.MessageHandler += h, h => msgConsumer.MessageHandler -= h)             .Where(arg => arg.Message.CorrelationID == message.MessageID); 

When I call response.Subscribe(...) I get System.ArgumentException "Error binding to target method."

I can make it work with Observable.FromEventPattern<EMSMessageEventArgs>(msgConsumer, "MessageHandler") but then it's got the event as a string and just not as clean.

Also I have IObservable<EventPattern<EMSMessageEventArgs>> rather than IObservable<EMSMessageEventArgs>

What I'd like to understand is: when should I use FromEvent over FromEventPattern? It seems a bit trial and error.

like image 227
baralong Avatar asked Jun 24 '11 04:06

baralong


1 Answers

"Use FromEvent for events structurally don't look like a .NET event pattern (i.e. not based on sender, event args), and use FromEventPattern for the pattern-based ones." - Bart De Smet (Rx team)

like image 146
Richard Anthony Freeman-Hein Avatar answered Sep 19 '22 11:09

Richard Anthony Freeman-Hein