【问题标题】:RX2 exception in EventLoopSchedulerEventLoopScheduler 中的 RX2 异常
【发布时间】:2014-02-27 17:13:35
【问题描述】:

我们已经从 RX1.1.11111.1 迁移到 RX 2.0.20823.2。现在我们遇到了一个来自 EventLoopScheduler 的罕见异常:

an Unhandled Exception occured in non UI thread.
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Reactive.Concurrency.EventLoopScheduler.Run()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

有没有人猜出问题出在哪里?是不是因为我们没有使用 onError 委托,我们的方法之一失败了?

这是代码的要点:

EventLoopScheduler m_scheduler = new EventLoopScheduler();

。 . .

m_receivedMessageHandler.StatusReceived.ObserveOn(m_scheduler) .Subscribe(p_unit => sendAll(m_retransmitManager, m_endPoint));

sendAll 中的异常会导致这种行为吗?

【问题讨论】:

  • 可能,但没有看到您的任何代码或扩展的堆栈跟踪信息,这是不可能的。
  • 拼写更正可能是值得的,但一些导致错误的实际代码绝对值得。请添加一些代码。

标签: system.reactive reactive-programming


【解决方案1】:

您需要在订阅中放置一个 onError 处理程序,否则应用程序将崩溃。如果您不关心错误,那么就吃掉它,不要做任何事情。我有一次同样的错误,所以我做了

            var subscription = observable.Subscribe(
                onNext: (v) => DoSomethingWith(v),
                onError: (Exception e) => {
                    // Just eat and log the exception.
                    Debug.WriteLine(e.ToString());
                }
            );

当我不关心异常时。如果这是一个真正的问题,最好明确地忽略错误和/或将其记录在某个地方。

【讨论】:

  • 其实我错了。如果没有使用 linq catch 语句处理,OnError 应该终止序列。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-26
  • 1970-01-01
  • 2021-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多