using System;
using System.Threading.Tasks;
using System.Threading;
public class Program
{
public static void Main()
var task = Task.Run(() => {
Thread.Sleep(4000); //4 seconds
return "hello1";
// if an exception in thrown from our async operation you need to capture that
// exception will be swallowed if you dont have logic to capture it
});
// Console.WriteLine(task.Result); // not good - blocks the application until there is a result available
task.ContinueWith((t) => {
if(t.IsFaulted){
//indicates that task have been completed with unhandled exception
Console.WriteLine("unhandled exception");
}
Console.WriteLine(t.Result);
// not good - running from the wrong thread - remember this is an async operation as well running on some other thread (not the main thread)