在 async
方法中如何处理 null
任务是最好的方式?
public class MyClass
{
private readonly Task task;
public MyClass(Task task) { this.task = task; }
public async Task Execute()
{
if (task == null)
{
await Task.Yield(); /* Is this the best way? */
return;
}
await task;
}
}
public MyClass(Task task){if (task == null)throw new ArgumentNullException("task");..}
- John Saunders