这是我一直看到的代码-
public Task PossiblyAsyncOperation(bool condition)
{
//this condition means i need to do something async, for sure
if (condition)
return AsyncOp();
//since it didnt hit the above condition
//we're not doing the async op now
//.....this just feels wrong
return Task.Factory.StartNew(() => { ; });
}
当您实际上不打算最终运行异步操作时,是否有更好的返回方式?还是您必须返回一个新的、已开始的任务?这对性能有影响吗?