Skip to content

Instantly share code, notes, and snippets.

@davkean
Created February 22, 2021 02:39
Show Gist options
  • Save davkean/7785a5f01654bcb94adcc1a26d87742f to your computer and use it in GitHub Desktop.
Save davkean/7785a5f01654bcb94adcc1a26d87742f to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        ManualResetEvent manual = new ManualResetEvent(false);

        for (int i = 0; i < 10000; i++)
        {
            Stopwatch watch1 = Stopwatch.StartNew();

            var local = i;
            Task.Run(() =>
            {
                watch1.Stop();
                Console.WriteLine($"#{local} Elapsed: {watch1.ElapsedMilliseconds} ThreadId: {Thread.CurrentThread.ManagedThreadId }");
                manual.WaitOne();
            });
        }

        manual.WaitOne();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment