Skip to content

Instantly share code, notes, and snippets.

@luisdeol
Created November 12, 2017 13:29
Show Gist options
  • Save luisdeol/80eb676dcd5dec25737a60b6b7a43b1b to your computer and use it in GitHub Desktop.
Save luisdeol/80eb676dcd5dec25737a60b6b7a43b1b to your computer and use it in GitHub Desktop.
Using the Thread Class
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