Roelant M
Roelant M

Reputation: 1706

does task.delay infinite code after it executed?

Just a quick question. We're having some misunderstanding here.

for simplicity some code is removed:

public async Task ConsumeAsync<T>(CancellationToken cancellationToken)
{
 _logger.LogInformation("consume async");

 await Task.Delay(Timeout.Inifite, cancellationToken);

      _logger.LogInformation("cancelled");
}

Should the last logline be logged or not when a cancel is requested?

Upvotes: 1

Views: 208

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500225

Should the last logline be logged or not when a cancel is requested?

No, because the task returned by Task.Delay will be faulted, as is normal when a task is cancelled.

Upvotes: 5

Related Questions