I was new to the async-await
method in C# 5.0
, and I have few questions in my mind
What is the best way to escape an
async
method if it failed an input argument or null check?What is the logical flow of using
return;
in an Taskasync
method (In some circumstances, it became an infinite loop)?Is
CancellationToken
orTask.Yield
fit better in this scenario?
public Func<AzureBlobInfo, string, Task> UploadSuccessCallBackAsync { get; set; }
private async Task OnUploadSuccessAsync(AzureBlobInfo info)
{
if (this.UploadSuccessCallBackAsync == null)
{
return;
}
var transactionType = this.FormData.Get("transactionType");
if (string.IsNullOrEmpty(transactionType))
{
transactionType = "unknown";
}
await this.UploadSuccessCallBackAsync(info, transactionType);
}