0

I want to schedule multiple work items to a single task, i.e. a single task should perform a task one after another. I know about .continuewith() functionality of tasks. My problem has two parts:

The first problem is that I also want to schedule priority to that task, I am using the scheduler suggested by romkyn in this post.

Is there any way that the same task should perform multiple works under the same priority level?

I am generating over a 100 tasks and schedule them with randomly assigned priority level, i.e. lowerst, above normal...highest.

During the generation and execution phase, how am I supposed to (a)know and (b)cancel the task which is executing using the taskcancellationtoken, if a task with higher priority level is generated and cannot wait?

For now, I am using a simple for loop and taskfactory to generate tasks.

Task t = Task.Factory.StartNew(() =>
{
         //perform work1 here
 }, ct, TaskCreationOptions.None, PriorityScheduler.Lowest);
Community
  • 1
  • 1
faizanjehangir
  • 2,771
  • 6
  • 45
  • 83
  • 1
    "with randomly assigned priority level" That doesn't sound like a good idea. You should create low priority tasks for things low priority and otherwise assign correct priorities to things, not random. – Tony The Lion Sep 25 '12 at 08:25
  • 1
    If you are randomly generating the priority of the tasks then how is the one with the highest priority really the one with the highest priority? It seems to me that it only got that priority through the luck of the draw, not by any form of real merit. – Colin Mackay Sep 25 '12 at 08:26
  • Just for the sake of comparison, I am assigning the priorities to tasks randomly. So that I can graph the results I obtain and simulate the computation accordingly. – faizanjehangir Sep 25 '12 at 10:44

0 Answers0