Suppose I have a code as follows:
int Main()
{
if (true)
{
new Thread(()=>
{
doSomeLengthyOperation();
})
when does Thread A get destroyed?
When doSomeLengthyOperation finishes.
Will doSomeLenghtyOperation() be able to run into completion
Yes, even if the main thread exists because it is not a background thread. If you set the IsBackground property to true before starting the thread whenever the main thread exists, this thread will also be stopped.