方法完成后,此线程会发生什么情况? [英] What happens with this thread after the method finishes?

查看:85
本文介绍了方法完成后,此线程会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET应用程序中,在堆栈上放了一段时间,我调用了以下代码:

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

此线程正在运行时,将处理其余请求,并将响应发送给客户端.但是,由于我从不调用thread.Abort()之类的东西,并且对ASP.NET中的线程处理经验不足,因此我担心自己会为内存泄漏或其他线程问题敞开大门.

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.

Larma_Thread完成运行后,我从上面的代码开始的线程会发生什么情况?

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.

这篇关于方法完成后,此线程会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆