How to add priority task features

I am using the task library for the image compression service. I would compress a lot of concurrency files. But I want the service to start only when the user is idle (or no more impotent task in the program).

I know that threadPool does not support the function "change thread priority", so the task also supports this function.

Can I develop this functionality at a higher level of control (e.g. TaskScheduler priority)

+5
source share
2 answers

As @zengr mentioned, you can use the priority queue pattern to solve this problem. It’s actually a good example in MSDN to implement priority queues using ConcurrentQueue<T>instances of priority, and then wrap using a special IProducerConsumerCollection<T>implementation that pulls items from a queue with a higher priority to lower ones. This type of implementation allows your manufacturer to determine how many priorities should be, assign priority when an item is added, and allows your consumer to work with the highest priority first without ever having to understand the priority algorithm.

+4
source

TaskScheduler Parallel, , TaskFactory.

, :

+2

All Articles