What is the significance of Thread.Join in C#?
Join()
is basically while(thread.running){}
{
thread.start()
stuff you want to do while the other thread is busy doing its own thing concurrently
thread.join()
you won't get here until thread has terminated.
}
int fibsum = 1;
Thread t = new Thread(o =>
{
for (int i = 1; i < 20; i++)
{
fibsum += fibsum;
}
});
t.Start();
t.Join(); // if you comment this line, the WriteLine will execute
// before the thread finishes and the result will be wrong
Console.WriteLine(fibsum);