Created
January 31, 2018 16:14
-
-
Save mgravell/ca3e90396bd068d1a6c1200c2c93e92a to your computer and use it in GitHub Desktop.
TPL with one worker
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
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 |
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.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