If I run this code, will each AppDomain execute in a different thread?
ThreadPool.QueueUserWorkItem(delegate
{
/// Create AppDomain and run code
});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
AppDomains do not get their own thread per default. You may execute code in another AppDomain using existing threads or call a method in the AppDomain, that creates new thread(s). In fact, unless you specifically creates additional threads calling code in another domain will execute on the process’ main thread.
From the AppDomain documentation
In your example, you create threads (or more specifically the thread pool does so) and thus the code will run on these threads. However, I am not sure I would recommend creating AppDomains on thread pool threads like that.
Unloading an AppDomain will abort any threads in the AppDomain. I honestly don’t know how the thread pool will react to this. More info about unloading here.