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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timeout = Task.Delay(5000); | |
timeout.Start(); |
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().