Friday, February 24, 2012 2:36 PM
Given this sample code from the RX Design Guidelines PDF document...
What is the importance of the variable scheduler? It is used only in the throttle method of query. But does it also allow WPF updates on the WPF Thread too?
Also what exactly does this Lamda do?
d=>d.invoke, h=>TextBox.KeyUp+=, h=>TextBox.HeyUp-=
d.invoke what? and then it looks like it adds a handler and immediate removes it? That's a bit strange to me.
Finally the dictionarySuggest.Subscribe populates the ListVieww1.Items without regard to which thread it's on. Why wouldn't there be a cross thread update exception?
JP Cowboy Coders Unite!
Friday, February 24, 2012 5:49 PM
> What is the importance of the variable scheduler? [snip]
This particular scheduler causes Throttle to push notifications onto the UI thread in a WinForms application.
> But does it also allow WPF updates on the WPF Thread too?
No, ControlScheduler is for WinForms only. Use DispatcherScheduler instead for a WPF application. To get this scheduler, add a reference to System.Reactive.Windows.Threading.dll.
You can read more about scheduling here:
> Also what exactly does this Lamda do?
It's actually 3 different lambdas being passed as arguments to FromEvent (now called FromEventPattern). You can read about their purpose in the documentation:
You can read more about event conversions here:
> Finally the dictionarySuggest.Subscribe populates the ListVieww1.Items without regard to which thread it's on.
> Why wouldn't there be a cross thread update exception?
That's presumably why ControlScheduler is passed to Throttle. All notifications that Throttle generates are pushed onto the UI thread. Thus, the following SelectMany receives notifications on the UI thread.
Edit: Apparently this is required because of TakeUntil(keyDown). The keyDown observable must receive observers on the UI thread.
However, this example isn't complete. Assuming that AsyncLookupInDictionary pushes notifications on a different thread, then you'd still get a cross-thread exception. AsyncLookupInDictionary must also be pushing notifications on the UI thread.
Friday, February 24, 2012 5:56 PM
Note that I just edited my previous post (again) to fix my answer for your last question.
- Edited by Dave Sexton Friday, February 24, 2012 5:59 PM Update
Friday, February 24, 2012 11:59 PM
Analyzing response now...
JP Cowboy Coders Unite!