Reputation: 1048
I'm trying to make the correct use of a task scheduler, namely IOTaskScheduler
. I have an app that crawls web pages and for each request (which is a task) I am generating a new IOTaskScheduler
. Rather, should I have only one instance of IOTaskScheduler
and pass that to all web requests (tasks)?
Alternatively in which cases would it be preferred to generate separate task schedulers?
Upvotes: 2
Views: 443
Reputation: 171178
To answer the question: For this TaskScheduler
you need to share an instance so that many tasks can be multiplexed onto the few threads that this scheduler provides.
What you should do instead: You should not use this task scheduler at all. It does nothing special to make IO faster. Use a normal fixed concurrency scheduler that uses normal .NET threads.
Alternatively in which cases would it be preferred to generate separate task schedulers?
I don't know of any. Schedulers are meant to multiplex many tasks to few threads. Registering a single task with each scheduler limits what the scheduler can intelligently do.
For some schedulers it does not matter. For example for a scheduler that puts each task onto a new thread.
Upvotes: 4