i use Task Library for my image compression service. I would to compress many files concurrency. But i want the service run only when user is idle(or no more impotarnt task in programm).
I know that threadPool does not support "change thread priority" feature, so task also does support this feature.
Can i develop that functionality on higher level of control?(TaskScheduler priority for example)
2 Organize tasks by priority You should give your most urgent and important tasks high priority and rank them toward the top of your list. You should give your least urgent tasks lower priority and place them near the bottom of the list.
As @zengr mentioned, you can use a priority queue pattern to solve this problem. There's actually a good sample in MSDN of implementing priority queues using ConcurrentQueue<T>
instances per priority and then wrapping that with a custom IProducerConsumerCollection<T>
implementation that pulls items from the higher priority queue before lower ones. This type of implementation enables your producer to determine how many priorities there should be, assign the priority when the item is added and lets your consumer work on the items with the highest priority first without having to ever understand the priority algorithm.
You can create a custom TaskScheduler
for the Task Parallel library and then schedule tasks on that by passing an instance of it to the TaskFactory
constructor.
Here's one example of how to do that: Task Scheduler with priority
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With