Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Created December 7, 2012 17:15
Show Gist options
  • Save davidfowl/4234791 to your computer and use it in GitHub Desktop.
Save davidfowl/4234791 to your computer and use it in GitHub Desktop.
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