Merge branch 'master' into msbuilddll2
[mono.git] / mcs / class / corlib / System.Runtime.CompilerServices / ConfiguredTaskAwaitable_T.cs
index 67dbea593d3593b0290438da867b4b0004dc515d..b96b1cc6f377fcf8804ef705575310231959facb 100644 (file)
@@ -28,7 +28,9 @@
 
 #if NET_4_5
 
+using System.Threading;
 using System.Threading.Tasks;
+using System.Runtime.ExceptionServices;
 
 namespace System.Runtime.CompilerServices
 {
@@ -53,8 +55,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;
                        }