Skip to content

Instantly share code, notes, and snippets.

View pageaffairs's full-sized avatar

Ralph Mason pageaffairs

View GitHub Profile
@pageaffairs
pageaffairs / gist:91f2a6f31dec4e9af8c949d690bab7b2
Created February 4, 2021 00:03
ASP.NET application snippet: 4
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();
@pageaffairs
pageaffairs / gist:96f5eee016e37cad0920faf4fbd94882
Created February 3, 2021 23:52
ASP.NET application snippet: 3
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) {
@pageaffairs
pageaffairs / gist:0ce4a2adb0cce160e09d65544dfeb3b4
Last active February 4, 2021 07:49
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);
@pageaffairs
pageaffairs / gist:a570daaf1d21f437720d2c9ea0927e61
Created February 3, 2021 22:59
ASP.NET application snippet: 1
public async Task<ReturnType> DoSomethingAndReturnSomeValAsync()
{
DoSomething();
SomeType someObj = await DoSomethingElseAsync();
return new ReturnType(someObj);
}
private async Task<SomeType> DoSomethingElseAsync(){
...
}