What happens with this thread after the method finishes?
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 A开发者_如何学Gos 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?
After the thread's code finishes executing, the thread will be stopped and its resources reclaimed.
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.
精彩评论