I am interested in the Rx.Net. And looking at the [https://learn.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh211731(v=vs.103)][1]
[1]: Observable.FromEventPattern method. The two parameters: addHandler and removeHandler interest me. I thought this two handler won't execute, they are just the dummy parameter, and useless. So when I change the codes as below - Bind different handler to the button click event, the Observable doesn't trigger the Observer any more.
Anyone can explain a bit more about here why never invoked h(RoutedEventHandler) is important?
public MainWindow()
{
InitializeComponent();
IObservable<EventPattern<RoutedEventArgs>> clicks = Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(
h => {
Console.WriteLine("AddHandler for {the second button}");
secondButton.Click += AnotherHandler;
},
h=> secondButton.Click -= AnotherHandler);
clicks.SubscribConsole("Example");
}
private void AnotherHandler(object sender, RoutedEventArgs args)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("Button click");
}