开发者

How can I filter the events using Throttle

开发者 https://www.devze.com 2023-01-17 00:29 出处:网络
I\'m trying reactive-framework in a win-form. IObservable<IEvent<Mouse开发者_运维百科EventArgs>> mouseMoves = Observable.FromEvent<MouseEventArgs>(this, \"MouseMove\");

I'm trying reactive-framework in a win-form.

IObservable<IEvent<Mouse开发者_运维百科EventArgs>> mouseMoves = Observable.FromEvent<MouseEventArgs>(this, "MouseMove");
IObservable<IEvent<MouseEventArgs>> mouseDowns = Observable.FromEvent<MouseEventArgs>(this, "MouseDown");
IObservable<IEvent<MouseEventArgs>> mouseUps = Observable.FromEvent<MouseEventArgs>(this, "MouseUp");
var pointChanges = mouseMoves.Zip(mouseMoves.Skip(1), (prev, post) => new { Prev = prev, Post = post });
var mouseDrags = from d in mouseDowns
                 from p in pointChanges.TakeUntil(mouseUps)
                 select p;

I want to filter the mouseDrags, only those MouseUps more than 1 second after MouseDowns are needed. How?


from d in mouseDowns.Timestamp()
from p in pointChanges
    .TakeUntil(mouseUps)
    .SkipUntil(Observable.Timer(d.Timestamp + TimeSpan.FromSeconds(1.0)))
select p;
0

精彩评论

暂无评论...
验证码 换一张
取 消