Yes, it is because StartNew
does not understand async
methods. You need to unwrap them, as such:
return Task.Factory.StartNew(async () =>
{
await _writer.WriteAsync(responseJson.ToString() + ',');
await _writer.FlushAsync();
},
_cancel.Token,
TaskCreationOptions.DenyChildAttach,
_writeNetworkScheduler.ExclusiveScheduler).Unwrap();
(also, use the DenyChildAttach
option for tasks intended to be consumed by await
).