I'm trying to figure out how can I use Reactive Extensions and for that I've written this simple example:
namespace ReactiveTest
{
class Program
{
static void Main(string[] args)
{
var o = Observable.Generate(0, i => i < 10, x => AddAndWait(x), i => i * i);
Console.WriteLine("Before");
o.Subscribe(x => Console.WriteLine(x));
Console.WriteLine("After");
Console.ReadLine();
}
static int AddAndWait(int i)
{
Thread.Sleep(1000);
return i + 1;
}
}
}
After watching this video I would expect to see After
printed right after Before
but I get squares of numbers instead, and only after that has completed I get the After
message.
I understand that I'm blocking the thread but isn't that the point of this reactive stuff, to be able to surpass that limitations and continue in your main thread?