Created
May 11, 2018 03:04
-
-
Save halter73/6270b0c90372df2e1d2302b026b6cb39 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.Threading; | |
using System.Threading.Tasks; | |
namespace RunAsync | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
for (var i = 0; i < 1000; i++) | |
{ | |
TestRunAsync(i).Wait(); | |
} | |
Console.WriteLine("Done!"); | |
} | |
static async Task TestRunAsync(int testRun) | |
{ | |
var tcs = new TaskCompletionSource<object>(TaskContinuationOptions.RunContinuationsAsynchronously); | |
var mre = new ManualResetEventSlim(); | |
var tcsAwaiterTask = Task.Run(async () => | |
{ | |
await tcs.Task; | |
if (!mre.Wait(TimeSpan.FromSeconds(10))) | |
{ | |
Console.WriteLine("Tcs continuation ran inline in test run {0}. Stack trace: {1}", testRun, Environment.StackTrace); | |
throw new Exception(); | |
} | |
}); | |
var tcsSetterTask = Task.Run(() => | |
{ | |
tcs.SetResult(null); | |
mre.Set(); | |
}); | |
await tcsAwaiterTask; | |
await tcsSetterTask; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment