Skip to content

Instantly share code, notes, and snippets.

@mgravell
Created January 31, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgravell/ca3e90396bd068d1a6c1200c2c93e92a to your computer and use it in GitHub Desktop.
Save mgravell/ca3e90396bd068d1a6c1200c2c93e92a to your computer and use it in GitHub Desktop.
TPL with one worker
Main thread: 1
Worker thread: 1
Worker thread: 1
Worker thread: 4
Worker thread: 5
Worker thread: 6
Worker thread: 5
Worker thread: 4
Worker thread: 3
using System;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Main thread: {Environment.CurrentManagedThreadId}");
Action action = () => Console.WriteLine($"Worker thread: {Environment.CurrentManagedThreadId}");
Console.WriteLine();
Parallel.Invoke(action);
Console.WriteLine();
Parallel.Invoke(action, action, action, action, action, action, action);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment