We're working with ReactiveExtensions for .Net
We schedule code to run on the Thread Pool like this:
IDisposable myDisposable = Scheduler.Default.Schedule(() =>
{
int count = 0;
while (true)
{
Console.WriteLine(++count);
Thread.Sleep(500);
}
});
Console.ReadKey();
myDisposable.Dispose(); // WHY THIS DO NOTHING?!?!
Console.ReadKey();
As you can see this is a test code that run on a console application.
When I dispose the scheduled code, the code keeps running!
I have no flag that I can check, I cannot add an if statement to stop the scheduled code by myself.
Someone can explain this? Why do I get an IDisposable if it doesn't work? and why I'm not getting some kind of flag (CancellationToken??) for checking inside my code so I can terminate its running in a timely manner?
Thanks!