Does a thread close automatically?

前端 未结 7 1230
萌比男神i
萌比男神i 2021-01-01 10:49

Im using a gmail class so that my app can send me notification over gmail.

Its done like this:

public static void SendMessage(string message)
{
    N         


        
相关标签:
7条回答
  • 2021-01-01 11:16

    The thread will go out of scope and be available for garbage collection as soon as SendFromGmail finishes.

    So yes, it closes automatically.

    0 讨论(0)
  • 2021-01-01 11:17

    No need, it will return back to the thread pool and wait for other task, if none it will kill itself.

    0 讨论(0)
  • 2021-01-01 11:25

    The thread needs to be started once - at which point it will execute the code block assigned to it and exit.

    You don't need to explicitly clean up the thread in most cases (unless you want to bail out early for example )

    0 讨论(0)
  • 2021-01-01 11:26

    Yes it will close, but you should but a timeout in order to avoid zombies anyway if the main thread crash while the second thread is waiting for it.

    0 讨论(0)
  • 2021-01-01 11:27

    yes,definitely. it will close itself when it ends.

    0 讨论(0)
  • 2021-01-01 11:36

    Yes , the thread is closed by itself.

    That is when all instructions in the method run on the secodn thread have been called.

    0 讨论(0)
提交回复
热议问题