This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApiController : ApiController | |
{ | |
// Top-level method | |
public ActionResult HandleRESTApiCall(){ | |
SomeType someObj = DoSomethingAsync().Result; | |
return OkResult(someObj); | |
} | |
private async Task<SomeType> DoSomethingAsync(){ | |
var someData = await GetDataAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ResultType> DoWorkAsync() | |
{ | |
ResultType retVal; | |
try { | |
Task<APIResult> apiResultTask = CallAnAPIAsync(); | |
var fileName = CreateFileName(); | |
var apiResult = await apiResultTask; | |
await WriteToAFileAsync(fileName, apiResult); | |
retVal = await StartAsyncOperation(fileName); | |
} catch (RealException rex) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ReturnType> DoSomethingAndReturnSomeValAsync() | |
{ | |
DoSomething(); | |
SomeType someObj = await DoSomethingElseAsync(); | |
return new ReturnType(someObj); | |
} | |
private async Task<SomeType> DoSomethingElseAsync(){ | |
... | |
} |