D
D
Denis2016-02-10 11:56:55
.NET
Denis, 2016-02-10 11:56:55

How to programmatically trigger an event using Rx?

Hello.
When we work with events directly, everything is simple

ListBox lb = new ListBox();
lb.SelectedValueChanged += LbOnSelectedValueChanged;
....
private void LbOnSelectedValueChanged(object sender, EventArgs eventArgs)
{
....
}

where LbOnSelectedValueChanged is called when the event fires, and can also be called directly.
Or you can use Rx, where there is a logic for working with an event
IObservable<EventArgs> selectedValueChanged = Observable.FromEventPattern<EventHandler, EventArgs>(
                            h => lb.SelectedValueChanged += h,
                            h => lb.SelectedValueChanged -= h).Select(x => x.EventArgs);

            selectedValueChanged.Delay(TimeSpan.FromSeconds(10)).Where(ts =>
            {                
                return IsCorrect();
            }).Subscribe(x =>
            {
                .....
            });

The question is how to call this event (with the given logic) programmatically?
(i.e. how to pull the subscriber and call OnNext for selectedValueChanged is not clear)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question