Created
December 7, 2012 17:15
-
-
Save davidfowl/4234791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication10 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var task = TaskError(new InvalidOperationException()); | |
for (int i = 0; i < 500; i++) | |
{ | |
task = task.ContinueWith(t => TaskError(t.Exception)).Unwrap(); | |
} | |
var wh = new ManualResetEventSlim(); | |
task.ContinueWith(t => | |
{ | |
// It hangs here because the string is gigantic | |
Console.WriteLine(t.Exception.ToString()); | |
wh.Set(); | |
}); | |
wh.Wait(); | |
} | |
private static Task TaskError(IEnumerable<Exception> errors) | |
{ | |
var tcs = new TaskCompletionSource<object>(); | |
tcs.SetException(errors); | |
return tcs.Task; | |
} | |
static Task TaskError(Exception ex) | |
{ | |
var tcs = new TaskCompletionSource<object>(); | |
tcs.SetException(ex); | |
return tcs.Task; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment