问题描述
.NET中的线程之间是否有任何关系?我迫切需要从实际线程中获取父线程,并且无法移交这条信息.有什么方法可以在.NET中或使用Win32 API获取父线程?
Is there any relationship between threads in .NET? I urgently need to get the parent thread from the actual thread and there is no way to handover this piece of information.Is there any way to get parent thread in .NET or using the Win32 API?
有没有办法从其他任何线程获取父线程?
Is there any way to get parent thread from any other thread?
推荐答案
.NET不记录线程之间的父子关系.您需要通过在创建时将父线程传递给子线程来自行跟踪这些数据.
.NET does not record parent-child relationships between threads. You will need to track this data on your own, by passing the parent thread to the child on creation.
也就是说,我无法想象您为什么需要这个.是不是 Join
还是足够好?
That said, I cannot possibly imagine why you would need this. Isn't Join
ing from the parent or something good enough?
我可以理解,您可能会对诸如无论如何您想做什么?"之类的问题感到沮丧. -但是通常如果您让我们知道您的真正目标是什么,我们也许能够找到您没有想到的更好的方法. :)
I can understand that you might be frustrated by questions like "What are you trying to do, anyway?" - but often times if you let us know what your true goal is we may be able to find a better way that you didn't think of. :)
这篇关于如何从子线程或其他线程进入父线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!