Reputation: 2197
I'm having significant difficulty choosing between Scheduler.Default
and TaskPoolScheduler.Default
.
I've seen it suggested that the TaskPoolScheduler is more efficient/optimised and it certainly has the benefit of being more explicit/specific; however, that doesn't help me understand the real differences, given that functionally they appear to do the same thing.
When is Scheduler.Default
preferable to TaskPoolScheduler.Default
and vice versa?
Upvotes: 4
Views: 1135
Reputation: 12667
Scheduler.Default
is the same as DefaultScheduler.Instance
.
How does the DefaultScheduler
handle thunks? DefaultScheduler
sits on top of a platform abstraction layer that schedules work depending on what system it's on.
This used to be the System.Reactive.PlatformServices.dll
assembly, which would differ according to the plaform, but for 4.x it's just an empty facade assembly to stay compatible with 3.x, with the implementation moved to System.Reactive.dll
.
For DefaultScheduler:
ThreadPool
is used.SchedulePeriodic
) a System.Threading.Timer
is used.The details of what platform service is chosen is in the EnlightenmentProvider.
You could maybe use DefaultScheduler
when you have long-running computations or periodic events where TimeSpan is very small, or zero, although EventLoopScheduler
may be better.
Prefer TaskPoolScheduler
when possible. It's a lightweight implementation intended for short computations.
Upvotes: 6