C# Thread object lifetime

后端 未结 4 689
终归单人心
终归单人心 2020-12-01 12:46

Suppose I have a code as follows:

int Main()
{
    if (true)
    {
       new Thread(()=>
          {
              doSomeLengthyOperation();
          })         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 13:02

    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.

提交回复
热议问题