Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: [SOLVED] TableLayoutPanel and .. surprise surprise .. weird behaviour 8) Pin
Emanuele Bonin30-Jan-16 6:18
Emanuele Bonin30-Jan-16 6:18 
AnswerRe: TableLayoutPanel and .. surprise surprise .. weird behaviour 8) Pin
BillWoodruff30-Jan-16 2:39
professionalBillWoodruff30-Jan-16 2:39 
QuestionSubscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 2:18
mvaKenneth Haugland29-Jan-16 2:18 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Pete O'Hanlon29-Jan-16 3:25
mvePete O'Hanlon29-Jan-16 3:25 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:47
mvaKenneth Haugland29-Jan-16 4:47 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Richard Deeming29-Jan-16 5:03
mveRichard Deeming29-Jan-16 5:03 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 5:22
mvaKenneth Haugland29-Jan-16 5:22 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Richard Deeming29-Jan-16 3:31
mveRichard Deeming29-Jan-16 3:31 
I suspect the Rx libraries have changed since that message was posted in 2011.

In the version I have (2.2.0.0), the FromEvent overload that you're trying to call has the following signature:
C#
IObservable<TEventArgs> FromEvent<TDelegate, TEventArgs>(
    Func<Action<TEventArgs>, TDelegate> conversion, 
    Action<TDelegate> addHandler, 
    Action<TDelegate> removeHandler);

The conversion parameter that's causing confusion is a function which takes a single parameter (d) and returns an EventHandler instance. The parameter is an action which takes a single EventArgs parameter.

Therefore, d.Invoke has the signature:
C#
void Invoke(EventArgs e);

whereas the EventHandler delegate you're trying to return has the signature:
C#
void Invoke(object sender, EventArgs e);

Obviously, those signatures are not compatible. You need to return another lambda method / delegate which matches the EventHandler signature, and passes the second parameter (e) to the action (d):
C#
d => (sender, e) => d(e)

These nested lambdas can be quite confusing. Breaking it down, you end up with something similar to this:
C#
private sealed class TheClosure
{
    public Action<EventArgs> TheActionToCall;
    
    public void TheEventHandler(object sender, EventArgs e)
    {
        TheActionToCall(e);
    }
}

private static EventHandler Conversion(Action<EventArgs> d)
{
    TheClosure closure = new TheClosure();
    closure.TheActionToCall = d;
    return closure.TheEventHandler;
}

...

Func<Action<EventArgs>, EventHandler> conversion = Conversion;
return Observable.FromEvent<EventHandler, EventArgs>(conversion, ...).Select(ignored => getter(target));




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:56
mvaKenneth Haugland29-Jan-16 4:56 
AnswerRe: Subscribe to property changes using Reactive Extensions Pin
Sascha Lefèvre29-Jan-16 3:49
professionalSascha Lefèvre29-Jan-16 3:49 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 4:59
mvaKenneth Haugland29-Jan-16 4:59 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Sascha Lefèvre29-Jan-16 5:30
professionalSascha Lefèvre29-Jan-16 5:30 
GeneralRe: Subscribe to property changes using Reactive Extensions Pin
Kenneth Haugland29-Jan-16 5:51
mvaKenneth Haugland29-Jan-16 5:51 
QuestionEnable / Disable DNS Client service (c#) Pin
Member 1041097228-Jan-16 22:21
Member 1041097228-Jan-16 22:21 
AnswerRe: Enable / Disable DNS Client service (c#) Pin
Nathan Minier29-Jan-16 2:05
professionalNathan Minier29-Jan-16 2:05 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Member 1041097229-Jan-16 5:21
Member 1041097229-Jan-16 5:21 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Nathan Minier29-Jan-16 5:28
professionalNathan Minier29-Jan-16 5:28 
AnswerRe: Enable / Disable DNS Client service (c#) Pin
Eddy Vluggen29-Jan-16 2:19
professionalEddy Vluggen29-Jan-16 2:19 
GeneralRe: Enable / Disable DNS Client service (c#) Pin
Member 1041097229-Jan-16 5:25
Member 1041097229-Jan-16 5:25 
QuestionHow to change utc Date in a normal Date Pin
Member 1191673528-Jan-16 2:20
Member 1191673528-Jan-16 2:20 
AnswerRe: How to change utc Date in a normal Date Pin
Sascha Lefèvre28-Jan-16 3:06
professionalSascha Lefèvre28-Jan-16 3:06 
GeneralRe: How to change utc Date in a normal Date Pin
jschell29-Jan-16 12:26
jschell29-Jan-16 12:26 
AnswerRe: How to change utc Date in a normal Date Pin
Eddy Vluggen28-Jan-16 3:19
professionalEddy Vluggen28-Jan-16 3:19 
AnswerRe: How to change utc Date in a normal Date Pin
Midi_Mick28-Jan-16 14:00
professionalMidi_Mick28-Jan-16 14:00 
AnswerRe: How to change utc Date in a normal Date Pin
John Torjo28-Jan-16 19:54
professionalJohn Torjo28-Jan-16 19:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.