Nenad Birešev
Nenad Birešev

Reputation: 377

Task starts with delay

I create and start task in following way:

 Task task = new Task(() => controller.Play());
 task.Start();

For some reason, sometimes task get started with around 7-10 seconds delay. I use 6 tasks in parallel, max number of tasks is 32767 and available 32759 which is what i log before i create task so it can't be that max number of tasks is reached. I write log at the first line of code in controller.Play() method that task should execute, so there is no lock or anything that could make task to wait.

Upvotes: 0

Views: 208

Answers (1)

Nick
Nick

Reputation: 5042

Long running tasks, like your deserialization of 100MB that takes 10 seconds, should be, hm, well, run as long-running tasks :-)

Long-running tasks are, as per the current implementation, always run on a dedicated thread and they do not put pressure on the thread-pool.

In your case, you perhaps only two tasks - the deserialization and the player. The TaskScheduler works under the assumption that tasks are short-lived, and in this case, it obviously schedules the "player" task to run after the "deserializaion" one.

Upvotes: 1

Related Questions