I am new to C#.I learnt that normally all threads are foreground until unless you explicitly specify it as \"background\" thread using IsBackGround= true .
If the thread should complete before the program terminates, then it should not be a background thread.
There are lots of ways to make your main thread wait, but in the example above I think what you really want to do is to make sure it's not a background thread.
The Join method is generally used to make sure that threads are done executing before the calling thread continues. For example, you may spawn 5 threads that each do some math operation and the results of those operations may be needed to move on with the next step. The Join method will pause execution on the calling thread until the spawned threads can completed. It is important to note that if you call Join from the UI thread you will freeze your program until the spawned threads are finished.
In short, multi threading is really complicated and nuanced. I highly recommend buying a good book on the subject.