Как я понимаю, метод Subscribe должен быть асинхронным, тогда как Run - синхронным. Но этот кусок кода работает синхронно. Кто-нибудь может это исправить?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reactive.Linq;
namespace RxExtensionsDemo
{
class Program
{
static void Main(string[] args)
{
IObservable<int> source = Observable.Generate<int, int>(0, i => i < 10000, i => i + 1, i => i * i);
IDisposable subscription = source.Subscribe(x => { Console.WriteLine("Received {0} from source", x); }, ex =>
{
Console.WriteLine("Error occured");
}, () =>
{
Console.WriteLine("Source said there are no more messages to follow");
});
Console.WriteLine("Asynchronous");
Console.ReadKey();
}
}
}
Я всегда вижу Asynchronous, записанный в консоли в последний раз.