Get a Thread by name
Hi to all,
I don't know if this the exact forum to make this question. Well, I will do. I have a thread running which I have created, and I save its name. And I would like to know after a certain time, how to get "by name" to that thread and make a certain operation to it. Like abort it.
So many thanks to all,
Zodraz
[331 byte] By [
Zodraz] at [2007-12-16]
Hello,
Today, there isn't a bullet-proof way to query threads running in an AppDomain from inside the user-code itself. If you control the creation of the threads, you can save the thread object itself and use Abort.
!!HOWEVER!!
We strongly discourage [in fact, user-initiated Thread.Abort is essentially not recommended] aborting thread arbitrarily. While the Abort may execute gracefully, it may have more obscure side effects depending on your architecture and what code the thread is executing. For example, the Abort may not complete immediately or at all if it is executing unmanaged code or blocked in a finally block.
You can find more information at: http://msdn2.microsoft.com/en-us/library/ty8d3wta.aspx
If you use Abort, you might consider tearing down the AppDomain completely - essentially using Abort as a way to regain control of the AppDomain during cleanup.
Instead of using Abort, using a waitable event to allow the thread to exit gracefully, and designing the thread for incomplete termination is recommended.
If you use the CLR hosting APIs (native code), then you can control and query running threads.
Hope that helps,
Stephen Fisher