Feature req: change priorities. Or maybe, ForWaiting(Predicate<>)...

May 6, 2008 at 4:11 PM
I have a pool of long-playing tasks to be performed in different threads. STP fits greatly, thanks.

One thing: I need to change tasks priorities, or totally cancel them.

So I'm thinking about quick hack (is pseudocode):
STP.Cancel(WorkItemPriority least);
STP.DecreasePriorities(WorkItemPriority least);

or
STP.Cancel(x => x.Priority < WorkItemPriority.Normal);

or even
STP.ForWaiting(x => x.Priority < WorkItemPriority.Normal && x.Cancel());
STP.ForWaiting(x => x.Priority = x.Priority-1);
though latter breaks immutability and can mess things up a lot.

Is this reasonable and something that anyone else could need?
Coordinator
May 6, 2008 at 4:20 PM
Edited May 6, 2008 at 4:22 PM
Hi,

If you know in advance which work items you want to cancel, you can use the WorkItemsGroup.
Instead of queuing your work items into the STP queue them into a WorkItemsGroup.
When you want to cancel them, cancel the WorkItemsGroup.

As for changing the priority of a queued work item, this is complicated and has a performance impact.

Ami
May 7, 2008 at 2:43 PM
On WorkItemsGroup... it would be nice for it and STP to implement same interface - a set of QueueXXX().
I'm conditionally queuing several different functions, and would like to have a single object in the end to call QueueWorkItem() on, not another 'if'.
Coordinator
May 7, 2008 at 5:34 PM
Edited May 7, 2008 at 5:35 PM

singalen wrote:
On WorkItemsGroup... it would be nice for it and STP to implement same interface - a set of QueueXXX().

IWorkItemsGroup already implements the same interface as STP. i.e. QueueXXX().


I'm conditionally queuing several different functions, and would like to have a single object in the end to call QueueWorkItem() on, not another 'if'.

I don't understand what you need, can you show me a code snippet?
May 7, 2008 at 8:43 PM
amibar wrote:
singalen wrote:
On WorkItemsGroup... it would be nice for it and STP to implement same interface - a set of QueueXXX().
IWorkItemsGroup already implements the same interface as STP. i.e. QueueXXX().
Sorry, my bad. IWorkItemsGroup is what I need.