开发者

Do Threads halt automatically when its ThreadStart Routine returns?

开发者 https://www.devze.com 2023-04-05 00:12 出处:网络
I created a new thread and assigned it a function to execute with ThreadStart. Here an example: this.threadAppPtE = new Thread(new ThreadStart(synchronizeAppPte));

I created a new thread and assigned it a function to execute with ThreadStart. Here an example:

this.threadAppPtE = new Thread(new ThreadStart(synchronizeAppPte));

Does the thread halt automatically开发者_JAVA百科 when the function i assigned ends or do I have to end it manually?


http://msdn.microsoft.com/en-us/library/ms686724(v=vs.85).aspx

A thread executes until one of the following events occurs:

  • The thread calls the ExitThread function.
  • Any thread of the process calls the ExitProcess function.
  • The thread function returns.
  • Any thread calls the TerminateThread function with a handle to the thread.
  • Any thread calls the TerminateProcess function with a handle to the process.


Yes the thread will terminate automatically, as long as it's not blocked and completes it's work.Obviously you need to call threadAppPtE.Start() to kick it off in the first place.

To rejoin the thread, where it has not completed is more complex. There's a good article called Create and Terminate Threads which might be helpful to explain this process better.

0

精彩评论

暂无评论...
验证码 换一张
取 消