You need to specify the type parameters in Observable.Generate
explicitly so that it doesn't get confused with the non-generic IEnumerator. Try replacing your third line of code with:
replay = Observable.Generate<IEnumerator<WorkItem>,WorkItem>(
Question
I have following code where I try to replay sequence; but PostWorkItem always gets null; I don't understand why. Below code give Stack overflow error.
Task<List<WorkItem>> WorkItems = DbUtil.GetWorkItems(new List<string>() { WorkItemStatus.NEW, WorkItemStatus.PROCESSING });
Items = WorkItems.Result;
replay = Observable.Generate(
Items.GetEnumerator(),
events => events.MoveNext(),
events => events,
events => events.Current,
events => System.TimeSpan.FromMilliseconds(50),
var);
replay.Subscribe(
W =>
PostWorkItem(W)
);
//var.AdvanceBy(System.TimeSpan.FromSeconds(1));
var.Start();
Solution
You need to specify the type parameters in Observable.Generate
explicitly so that it doesn't get confused with the non-generic IEnumerator. Try replacing your third line of code with:
replay = Observable.Generate<IEnumerator<WorkItem>,WorkItem>(