Con risposta Getting Started

  • lunedì 30 aprile 2012 23:18
     
     

    Trying to play around with Rx v2.0 Beta and need some help.

    I have the following IObservable setup...

    private readonly Subject<int> _IncomingValue = new Subject<int>();

    public IObservable<int> IncomingValue { get { return _IncomingValue.AsObservable(); } }

    I have a Button click event that I want to begin looking for a certain value on IncomingValue and would also like to have a Timeout of 5 seconds.  If the Timeout occurs, it will display "Time is up" in a TextBox using WPF and unsubscibe.

    I have another Button click event that will use the IncomingValue.OnNext(iNewValue) to update to the value I'm looking for.

    Once the correct value is sent, I would like to unsubscribe so future events won't be triggered.

    How would I write this basic code?  Any solutions?  TIA.

Tutte le risposte

  • martedì 1 maggio 2012 11:59
     
     Con risposta

    Hi,

    Here's a blog post that contains links to get started learning Rx:

    http://davesexton.com/blog/post/resources-for-learning-rx.aspx

    For your particular questions, I highly recommend reading Rx's conceptual documentation.  All of it's worth reading, but you may want to start here:

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

    Also, you should try searching this forum if you haven't already.  Your questions are a bit vague, but I'm sure they've been answered here before.

    Here are some hints:

    > I have a Button click event that I want to begin looking for a certain value on IncomingValue

    Consider using the Where operator.

    > Timeout of 5 seconds.

    Consider using the Timeout operator.

    > If the Timeout occurs, it will display "Time is up" in a TextBox using WPF

    Consider using the Catch operator.  You may also want to consider using some type for T (of the Subject<T>) that may pass either success information or timeout information to subscribers.  For example, see the Either type in Rxx; e.g., Either<int, TimeoutException>.  Or you could write directly to the TextBox as a side-effect in your Catch handler, though I don't recommend it.

    > Once the correct value is sent, I would like to unsubscribe so future events won't be triggered.

    Consider using the Take(1) operator.

    - Dave


    http://davesexton.com/blog

    • Contrassegnato come risposta shaggygi martedì 1 maggio 2012 13:46
    •