public async Task CaveatsOfTaskFactoryStartNew()
{
var tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(1));
var token = tokenSource.Token;
Task<Task> pumpTask = Task.Factory.StartNew(async () =>
{
while (!token.IsCancellationRequested)
{
#region Output
"Pumping...".Output();
#endregion
await HandleMessage().ConfigureAwait(false);
}
}, TaskCreationOptions.LongRunning);
await pumpTask.Unwrap().ConfigureAwait(false);
tokenSource.Dispose();
}