문제

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)

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top