What happens with this thread after the method finishes?

我与影子孤独终老i 提交于 2019-12-12 03:42:49

问题


In my ASP.NET application, a while down the stack I call the following code:

Public Shared Sub Larma(ByVal personId As Integer)
    Dim thread As New System.Threading.Thread(New ParametrizedThreadStart(AddressOf Larma_Thread))
    thread.Start(personId)
End Sub

Private Shared Sub Larma_Thread(ByVal personId As Integer)
    StartaLarm(personId)
    Thread.Sleep(1000 * 30)
    StoppaLarm(personId)
End Sub

While this thread is running, the rest of the request is handled and a response is sent to the client. However, since I never call thread.Abort() or anything of the like, and I am very inexperienced with threading in ASP.NET, I am worried that I'm opening up for memory leaks or other threading problems.

What happens with the thread I start with the code above after Larma_Thread finishes running?


回答1:


After the thread's code finishes executing, the thread will be stopped and its resources reclaimed.




回答2:


The thread will be terminated once your work is done.

Note that the thread might also be terminated before your work has finished I'd IIS decides it needs to recycle the ASP.NET worker thread.



来源:https://stackoverflow.com/questions/3046329/what-happens-with-this-thread-after-the-method-finishes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!