Looking at the Reactive Extensions for javascript demo on Jeff Van Gogh's blog, I thought I'd give it a try in C#/Winforms, but it doesn't seem to work so well.
I just threw this into the constructor of a form (with the Rx framework installed and referenced):
Observable.Context = SynchronizationContext.Current;
var mousemove = Observable.FromEvent<MouseEventArgs>(this, "MouseMove");
var message = "Time flies like an arrow".ToCharArray();
for(int i = 0; i < message.Length; i++)
{
var l = new Label()
{
Text = message[i].ToString(),
AutoSize = true,
TextAlign = ContentAlignment.MiddleCenter
};
int closure = i;
mousemove
.Delay(closure * 150)
.Subscribe(e =>
{
l.Left = e.EventArgs.X + closure * 15 + 10;
l.Top = e.EventArgs.Y;
//Debug.WriteLine(l.Text);
});
Controls.Add(l);
}
When I move the mouse, the letters seem to get moved in a random order, and if I uncomment the Debug line, I see multiple events for the same letter...
Any ideas? I've tried Throttle, but it doesn't seem to make any difference. Am I just asking too much of WinForms to move all those labels around?
(Cross posted on Rx Forum)