Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SitePointEditors/5d93de246850a964898fb5ca5fa7dfc1 to your computer and use it in GitHub Desktop.
Save SitePointEditors/5d93de246850a964898fb5ca5fa7dfc1 to your computer and use it in GitHub Desktop.
ASP.NET application snippet: 2
public ResultType DoWork()
{
ResultType retVal;
try {
var apiResult = CallAnAPIAsync().Result;
var fileName = CreateFileName();
WriteToAFileAsync(fileName, apiResult).Wait();
retVal = StartAsyncOperation(fileName).GetAwaiter().GetResult();
} catch (AggregateException aex) {
HandleError(aex);
retVal = null
}
return retVal;
}
private async Task<APIResult> CallAnAPIAsync() {...}
private async Task WriteToAFileAsync() {...}
private Task<ResultType> StartAsyncOperation(string fileName) {...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment