Created
November 12, 2017 13:29
-
-
Save luisdeol/80eb676dcd5dec25737a60b6b7a43b1b to your computer and use it in GitHub Desktop.
Using the Thread Class
This file contains hidden or 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
namespace MultiThreadingExamples | |
{ | |
public static void UltraCoolMethod() | |
{ | |
const int iterationNumber = 10; | |
for (var i = 0; i < iterationNumber; i++) | |
{ | |
Console.WriteLine($"Execution Thread Nº {i}"); | |
Thread.Sleep(0); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Thread theThread = new Thread(new ThreadStart(UltraCoolMethod)); | |
// You can do it Implicitly as well | |
// Thread theThread = new Thread(UltraCoolMethod); | |
theThread.Start(); | |
for (var i = 0; i < 5; i++) | |
{ | |
Console.WriteLine("Hey, the main thread is still doing stuff!"); | |
Thread.Sleep(0); | |
} | |
theThread.Join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment