I need a task that never ends until cancellation is requested. At the moment the simplest way to do that is:
var cancellation = new CancellationTokenSource();
var task = Task.Factory.StartNew(async () =>
{
while (true)
{
await Task.Delay(10000, cancellation.Token);
}
}, cancellation.Token).Unwrap();
What I don't like is a call to Task.Delay
method because it requires limited time interval for waiting.
Is there more elegant solution?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…