Unanswered Newbie Question from RX design Guidelines

  • 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!

All Replies

  • Friday, February 24, 2012 5:49 PM
     
     

    Hi,

    > 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:

    http://msdn.microsoft.com/en-us/library/hh242963(v=vs.103).aspx

    > 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:

    FromEventPattern
    http://msdn.microsoft.com/en-us/library/hh229922(v=vs.103).aspx

    You can read more about event conversions here:

    http://msdn.microsoft.com/en-us/library/hh242978(v=vs.103).aspx

    > 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.

    - Dave


    http://davesexton.com/blog

    • Edited by Dave Sexton Friday, February 24, 2012 5:55 PM More info about cross-thread error
    • Edited by Dave Sexton Friday, February 24, 2012 5:59 PM More info about cross-thread error
    •  
  • Friday, February 24, 2012 5:56 PM
     
     

    Hi,

    Note that I just edited my previous post (again) to fix my answer for your last question.

    - Dave


    http://davesexton.com/blog

    • 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!