Is it possible to move worker thread between AppDomains
I have to create procedure that will do fast close of multiple threads. My ide开发者_运维技巧a is to move all threads that has to be cancelled into new AppDomain, then abort all such threads and then unload that AppDomain.
Is that possible?
You cannot move threads between app domains. Objects aren't actually moved between them.
See Moving objects across AppDomains in .NET.
I believe you will just need to handle the thread objects yourself and cancel them as needed.
Aborting threads is a bad idea. Consider implementing cooperative cancellation. See how it's done in .Net 4 here. Here is a quote from that article:
Any asynchronous technique has the common trait that the target of cancellation is caught completely unaware and cannot easily ensure data safety. For many reasons, but particularly due to the risk of partial updates to shared data, the use of asynchronous techniques is strongly discouraged.
精彩评论