0

我们已经从 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 中的异常会导致这种行为吗?

4

1 回答 1

0

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

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

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

于 2012-11-08T12:32:53.767 回答