Skip to content

Instantly share code, notes, and snippets.

@BillWagner
Last active December 12, 2017 16:04
Show Gist options
  • Save BillWagner/78003137467eaa72e8e18a0d1272f814 to your computer and use it in GitHub Desktop.
Save BillWagner/78003137467eaa72e8e18a0d1272f814 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
public class Example
{
public static async Task<int> Main()
{
Console.WriteLine("Calling DoWorkAsync");
var taskResult = DoWorkAsync(-5);
Console.WriteLine("This hasn't thrown yet.");
Console.WriteLine($"Is the task faulted: {taskResult.IsFaulted}");
var returnCode = await taskResult;
Console.WriteLine("After Await");
return returnCode;
}
public static async Task<int> DoWorkAsync(int argument)
{
if (argument < 0)
throw new ArgumentException(message: "Don't go negative", paramName: nameof(argument));
await Task.Delay(argument);
return argument;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment