Let's say I have a non default app domain. I want to get a reference to the Default app domain and cause a thread to be created within it, that runs a piece 开发者_如何转开发of code. Is this possible? The only way I can think of doing this is to re-load my assembly into the Default app domain and have some logic in one of the constructors of a type that figures out it's been reloaded for the purpose of launching this new thread. That seems rather convoluted. Is there a more direct way of doing this? On the other hand if there were a way of doing it, it would seem that would circumvent the entire security model of .NET.
var ad = AppDomain.CreateDomain("mydomain");
ad.DoCallBack(() =>
{
var t = new System.Threading.Thread(() =>
{
Console.WriteLine();
Console.WriteLine("app domain = "
+ AppDomain.CurrentDomain.FriendlyName);
});
t.Start();
});
Try this. In the example, the call to GetAssemblyNames on the host instance is called in the second AppDomain. That method could easily start a thread to call your code.
精彩评论