本文介绍了Rx 中的历史调度器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码尝试重播序列;但 PostWorkItem 总是为空;我不明白为什么.下面的代码给出了堆栈溢出错误.

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();

推荐答案

您需要在 Observable.Generate 中明确指定类型参数,以免与非泛型 IEnumerator 混淆.尝试将第三行代码替换为:

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>(

这篇关于Rx 中的历史调度器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 17:03