using System.Threading.Tasks;
public static void Main()
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
var task=AsyncMain(token);
Console.WriteLine("Main after started thread");
Console.WriteLine("Main after task finished");
catch (AggregateException )
Console.WriteLine("Exceptions in Task");
public static async Task AsyncMain(CancellationToken token)
Console.WriteLine("In Thread at Start");
await Task.Delay(10).ContinueWith(async task =>
Console.WriteLine("Not Cancelled");
catch(TaskCanceledException)
{Console.WriteLine("Cancelled");}
Console.WriteLine("In Thread after Task");