开发者

How to get an instance of a thread from its name/id?

Is it possible to get开发者_运维技巧 the instance of a specific running thread knowing its name or id? If yes, how?


Not sure if there's a more direct way but in the worst case you should be able to loop through all the threads in Process.Threads and checking the ProcessThread.Id of them.

Here's the MSDN doc for ProcessThread properties.


You could try something like this:

Thread thread = Process.GetCurrentProcess().Threads.Single(t => t.ManagedThreadId == threadId);


You forgot to use Cast.

Process.GetCurrentProcess().Threads.Cast<ProcessThread>().Single(t => t.ManagedThreadId == threadId);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜