Created
December 21, 2015 09:00
-
-
Save BojanKomazec/d7fc71870b428cd8f087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Program.MainAsync().Wait(); | |
} | |
private static async Task MainAsync() | |
{ | |
var cancellationTokenSource = new CancellationTokenSource(); | |
var token = cancellationTokenSource.Token; | |
cancellationTokenSource.Cancel(); | |
var task = Task.Run(() => {}, token); | |
try | |
{ | |
await task; | |
} | |
catch(Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
Console.WriteLine($"Task.IsCanceled: {task.IsCanceled}"); | |
Console.WriteLine($"Task.IsFaulted: {task.IsFaulted}"); | |
Console.WriteLine($"Task.Exception: {((task.Exception == null) ? "null" : task.Exception.ToString())}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment