I'm trying to understand the changing behavior when I uncomment the 2nd SubscribeOn.
In this case, I hit the line throwing exception.
Can someone provide me with an answer - if it is intended behavior and why?
Without 2nd SubscribeOn it takes 30+ seconds to finish (and that's good). With - it hits the line with an exception after 2 seconds of run.
[TestMethod]
public void AsyncObservable_NonReentrant()
{
int tester = 0;
bool finished = false;
Observable.Generate(
0,
i => i < 5,
i => i+1,
i => i,
_ => TimeSpan.FromSeconds(1)
)
.SubscribeOn(ThreadPoolScheduler.Instance)
.Finally(()=>finished = true)
.Select(_ =>
{
Interlocked.Increment(ref tester);
if (tester > 1)
throw new InvalidOperationException();
return Observable
.Repeat(1, 5)
.Window(3)
.Finally(()=>Interlocked.Decrement(ref tester))
/*.SubscribeOn(ThreadPoolScheduler.Instance)*/;
})
.Concat()
.Subscribe(__ =>
{
Thread.Sleep(3000);
});
while (!finished)
Thread.Sleep(100);
}