Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created July 6, 2019 13:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save EgorBo/664bdfaa32761da497cfa3d7afdfa29d to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp166
{
class Program
{
static unsafe void Main(string[] args)
{
LongContinuationChain_ContinueWith_DoesNotStackOverflow();
Console.WriteLine("Done");
}
public static void LongContinuationChain_ContinueWith_DoesNotStackOverflow()
{
var tcs = new TaskCompletionSource<bool>();
var t = (Task)tcs.Task;
for (int i = 0; i < 12_000; i++)
{
t = t.ContinueWith(_ => { }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
}
tcs.TrySetResult(true);
t.Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment