Thursday, February 20, 2014

Task Parallel Library: Start may not be called on a promise-style task

A colleague was implementing some async stuff when he was confronted with the following error message:

Start may not be called on a promise-style task

Let’s have a look at his code and then explain where this error comes from:

Tne problem is caused by the fact that the underlying task is already started when you call Task.Delay. So calling Start(again) on the Task will throw the error mentioned above.

You can wait for the Task results using the await keyword or use the continuation style by using ContinueWith().

No comments: