使用 Reactive.NET,我如何才能等到同一事件发生 n 秒后再执行操作?
以下示例(C#,WinForms)正在做我想做的事,但我想要在扩展发生之前延迟(比如说 1 秒):
var autoExpand = Observable.FromEventPattern<DragEventArgs>(tree, "DragOver");
autoExpand
.ObserveOn(SynchronizationContext.Current)
.Distinct(dragEvent => tree.GetNodeFromCoordinates(dragEvent.EventArgs.X, dragEvent.EventArgs.Y))
.Subscribe(dragEvent => {
TreeNode node = tree.GetNodeFromCoordinates(dragEvent.EventArgs.X, dragEvent.EventArgs.Y);
if (node != null) node.Expand();
});