Skip to content

Instantly share code, notes, and snippets.

@alx9r
Created October 11, 2017 16:53
Show Gist options
  • Save alx9r/510d3bffa7a54394259af6783d332393 to your computer and use it in GitHub Desktop.
Save alx9r/510d3bffa7a54394259af6783d332393 to your computer and use it in GitHub Desktop.
Task<TResult>.Result throws exception
using System;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class Thrower
{
public string Throw()
{
throw new System.Exception("some exception");
return "return value";
}
public System.Func<string> GetThrow
{
get { return Throw; }
}
}
class Program
{
static void Main(string[] args)
{
Task<string> t = new Task<string>((new Thrower()).GetThrow);
t.Start();
Console.WriteLine(t.Result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment