为什么不调用 Rx.NET Finally 块?

Why the Rx.NET Finally block is not called?

请遵守以下简单的Rx.NET程序:

using System;
using System.Diagnostics;
using System.Reactive.Linq;

namespace observables
{
    class Program
    {
        static void Main()
        {
            var src = Observable
                .Interval(TimeSpan.FromMilliseconds(1))
                .Take(1)
                .Do(o => Debug.WriteLine(o))
                .Finally(() => Debug.WriteLine("************ Finally"));
            src.GetAwaiter().GetResult();
        }
    }
}

它显示:

0
************ Finally

现在,当我从 monad 中删除 Do 块时,程序不显示任何内容!

为什么?

Observable 线程和主线程之间存在竞争条件。

函数调用 src.GetAwaiter().GetResult(); 不等待 Observables Finally 因为它 运行 在不同的线程上。

多次尝试 运行:您会发现 Debug.WriteLine 偶尔会成功,至少在我的 Visual Studio 设置中是这样。