How can I generate a list of number with Rx.Net, like 0-100, where each number is generated at a random time?
edit:
seems like this works
public void NonBlocking_event_driven()
{
var random = new Random();
var ob = Observable.Create<int>(
observer =>
{
timer.Interval = 1000;
timer.Elapsed += (s, e) => observer.OnNext(random.Next(0, 3));
timer.Elapsed += OnTimerElapsed;
timer.Start();
return Disposable.Empty;
});
var subscription = ob.Subscribe(UserAction);
Console.ReadLine();
subscription.Dispose();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
var random = new Random();
timer.Interval = random.Next(1, 10)*1000;
Console.WriteLine(e.SignalTime);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…