简体   繁体   English

在多线程应用程序中中止线程时的内存状态

[英]Memory status when thread was being aborted in multi-threaded application

I didn't find a relevant search hit about what will happen to the memory a thread is using when is it being aborted, if it is a multi-threaded application. 如果线程是多线程应用程序,则在中断线程时正在使用的内存将发生什么,我没有找到相关的搜索命中。

Will there will any memory leak? 会不会有内存泄漏?

Also, if I didn't call Thread.ResetAbort() in catch clause will exception ThreadAbortException be thrown to the outer catch and outer catch if any... 另外,如果我没有在catch子句中调用Thread.ResetAbort() ,则会将ThreadAbortException异常抛出到外部catch和外部catch(如果有)...

Thanks. 谢谢。

  • Threads do not use memory. 线程不占用内存。 Processes have memory. 进程有内存。 Threads run in their parent process. 线程在其父进程中运行。

  • In C# objects allocated by an object are not different depending which thread has allocated them. 在C#中,对象分配的对象没有什么不同,具体取决于哪个线程分配了它们。 Read up on garbage collection. 阅读垃圾回收。

Also, if I didn't call Thread.ResetAbort() in catch clause will exception ThreadAbortException be thrown to the outer catch and outer catch if any... 另外,如果我没有在catch子句中调用Thread.ResetAbort(),则会将ThreadAbortException异常抛出到外部catch和外部catch(如果有)...

There is something called a documentation and this is a VERY simple lookup there. 有一种叫做文档的东西,这是一个非常简单的查找。 Let me quote for you. 让我为你报价。 All I did was type "ThreadAbortException" into google, which leads me to 我所做的就是在Google中键入“ ThreadAbortException”,这使我

https://msdn.microsoft.com/en-us/library/system.threading.threadabortexception%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 https://msdn.microsoft.com/zh-cn/library/system.threading.threadabortexception%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Now the quote: 现在报价:

When a call is made to the Abort method to destroy a thread, the common language runtime throws a ThreadAbortException. 调用Abort方法销毁线程时,公共语言运行库将引发ThreadAbortException。 ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block. ThreadAbortException是可以捕获的特殊异常,但是它将在catch块的末尾自动再次引发。 When this exception is raised, the runtime executes all the finally blocks before ending the thread. 引发此异常时,运行时将在结束线程之前执行所有的finally块。 Because the thread can do an unbounded computation in the finally blocks or call Thread.ResetAbort to cancel the abort, there is no guarantee that the thread will ever end. 因为线程可以在finally块中执行无界计算或调用Thread.ResetAbort取消中止,所以不能保证线程将永远结束。 If you want to wait until the aborted thread has ended, you can call the Thread.Join method. 如果要等待中止的线程结束,则可以调用Thread.Join方法。 Join is a blocking call that does not return until the thread actually stops executing. Join是一个阻塞调用,直到线程实际停止执行后才返回。

Simple like that. 这样简单。 It automatically is rethrown at the end of the catch. 在捕获结束时自动将其重新抛出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM