This project has moved and is read-only. For the latest updates, please go here.

Creating a Reactive Lab

The following procedure illustrates how to add a new Console Lab to the Hands-on Labs project.
Note: You must install the Labs Framework to use this procedure.
  1. Add a new item.
  2. Select the Console Lab template.
  3. Start coding your lab.

Figure 1: Add a new item to the Reactive folder.


Figure 2: Select the Console Lab template in the Add New Item dialog.


Figure 3: Start coding in the Main method.

using System;
using System.ComponentModel;
using System.Reactive.Linq;
using Rxx.Labs.Properties;

namespace Rxx.Labs.Reactive
    public sealed class MyFirstLab : BaseConsoleLab
        protected override void Main()
            // Prompt the user for input.
            int take;
            while (!int.TryParse(UserInput("How many items? "), out take)) { }

            // Show instructions to the user.

            // Initialize lab state and observables.
            var xs = Observable.Interval(TimeSpan.FromSeconds(1)).Take(take);

            // Subscribe the base ConsoleOutput method (without invoking it).
            using (xs.Subscribe(ConsoleOutput))
                // Optionally allow the user to cancel the subscription 
                // by pressing a key.

            // Alternatively, use the ForEach method instead of Subscribe to block
            // until the observable completes.

Last edited Feb 14, 2012 at 4:52 AM by davedev, version 5