Q:

ToTask makes OnCompleted execute on different thread

Code:
var sc = new TestScheduler();

Observable.Timer(TimeSpan.FromSeconds(5), sc)
          .ToTask()
          .ToObservable()
          .Do(_ => Console.WriteLine("on next: " + Thread.CurrentThread.ManagedThreadId), 
             () => Console.WriteLine("on complete: " + Thread.CurrentThread.ManagedThreadId))
          .Subscribe();

Console.WriteLine("call: " + Thread.CurrentThread.ManagedThreadId);
sc.AdvanceBy(TimeSpan.FromSeconds(5).Ticks);

Output:
call: 11
on next: 8
on complete: 8

If you remove both ToTask and ToObservable then everything will execute on the same thread. It seems to me that TPL schedules OnCompleted to Task Pool somehow, but I can't find it in the source code.
Can anybody help me understand what is going on here?
DotNetFiddle link: https://dotnetfiddle.net/epqTAG

A:

Task.ToObservable() uses Task.ContinueWith() to add a Task continuation to trigger the observable when the task completes.  By default, Task.ContinueWith() schedules the continuation on the task pool.
Rx.Net recently added an overload of ToObservable that accepts an IScheduler.
See the the Rx.Net github issue for more details.

