Merge pull request #1057 from lextm/master
[mono.git] / mcs / class / corlib / System.Runtime.CompilerServices / TaskAwaiter_T.cs
index c0af984ee559c209e0ba021803ad673703a68f6b..b59a0ef005e3736eed23103ee90f822c9dd2f6b7 100644 (file)
@@ -29,7 +29,9 @@
 
 #if NET_4_5
 
+using System.Threading;
 using System.Threading.Tasks;
+using System.Runtime.ExceptionServices;
 
 namespace System.Runtime.CompilerServices
 {
@@ -50,8 +52,11 @@ namespace System.Runtime.CompilerServices
 
                public TResult GetResult ()
                {
+                       if (!task.IsCompleted)
+                               task.WaitCore (Timeout.Infinite, CancellationToken.None, true);
+
                        if (task.Status != TaskStatus.RanToCompletion)
-                               throw TaskAwaiter.HandleUnexpectedTaskResult (task);
+                               ExceptionDispatchInfo.Capture (TaskAwaiter.HandleUnexpectedTaskResult (task)).Throw ();
 
                        return task.Result;
                }