user1400995
user1400995

Reputation:

Reactive Linq Observable doesn't notify when an event is fired

I am trying to get my head around the Observable pattern and basically fix an issue on an existing code that doesn't notify when an event is fired.

The event that I am observing is the ResizeGroupItemEnded defined as:

public event EventHandler<StGroupItemsModified> ResizeGroupItemEnded

So, the setup of the pattern is as follows:

private readonly IDisposable _groupUpdates;
private static readonly TimeSpan UpdateThrottle = TimeSpan.FromMilliseconds(300);
...
_groupUpdates = Observable.FromEventPattern<EventHandler<StGroupItemsModified>, PropertyChangedEventArgs>(e => groupUICtrl.ResizeGroupItemEnded += e, e => groupUICtrl.ResizeGroupItemEnded -= e)
                          .Throttle(UpdateThrottle)
                          .ObserveOn(SynchronizationContext.Current)
                          .Subscribe(x => RefreshVLines());
...
public void Dispose()
{
...
}

private void RefreshVLines()
{
  // We should be notified here when groupUICtrl.ResizeGroupItemEnded triggers
}

Why is RefreshVLinesStep() not called when groupUICtrl.ResizeGroupItemEnded is triggered? Any ideas please?

Upvotes: 0

Views: 258

Answers (1)

Dmitrii Dovgopolyi
Dmitrii Dovgopolyi

Reputation: 6301

You are using wrong generic arguments. Your code actually throws System.ArgumentException exception

You should change PropertyChangedEventArgs to actual event args, which are StGroupItemsModified

_groupUpdates = Observable.FromEventPattern<EventHandler<StGroupItemsModified>, StGroupItemsModified>(e => groupUICtrl.ResizeGroupItemEnded += e, e => groupUICtrl.ResizeGroupItemEnded -= e)
                          .Throttle(UpdateThrottle)
                          .ObserveOn(SynchronizationContext.Current)
                          .Subscribe(x => RefreshVLines());

Or you could simplify it by using this overload

Observable.FromEventPattern<StGroupItemsModified>(...)

Upvotes: 2

Related Questions