I want to start a subprocess and watch it’s redirected output. That not
a problem for me in C#, but I try to understand RX, so the game begins …
I have a static extension method for process, which looks like this:
public static IObservable<IEvent<DataReceivedEventArgs>> GetOutput(this Process that)
{
return Observable.FromEvent<DataReceivedEventArgs>(that, "OutputDataReceived");
}
I create an observable and subscribe to it like this:
Process p = ........
var outObs = p.GetOutput();
var outSub = outObs.Subscribe(data => Console.WriteLine(data));
This is not completely wrong, but I am getting:
System.Collections.Generic.Event`1[System.Diagnostics.DataReceivedEventArgs]
while I am expecting to get strings 🙁
So, I think, my extensionmethod returns the wrong type.
It would be really good, if someone could explain me, what’s
wong with my extension methods signature.
Thanks a lot,
++mabra
That’s exactly it.
IEvent wraps both the
senderand theEventArgsparameters of a tradition Event delegate. So you need to modify your code to look something likeIf you’re using the latest Rx, then the code is a bit different
the key here is to
SelecttheEventArgsfrom the EventPattern/IEvent, and then grab theData