1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| static void GetAllAppDomains() {
AppDomain one = AppDomain.CreateDomain("One"); AppDomain two = AppDomain.CreateDomain("Two");
List<AppDomain> appDomains = new List<AppDomain>();
IntPtr enumHandle = IntPtr.Zero;
ICorRuntimeHost host = null; host = GetCorRuntimeHost();
try {
host.EnumDomains(out enumHandle);
object domain = null;
AppDomain tempDomain;
while (true) {
host.NextDomain(enumHandle, out domain);
if (domain == null) { break; }
tempDomain = domain as AppDomain;
appDomains.Add(tempDomain);
}
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
finally { host.CloseEnum(enumHandle); int rel = Marshal.ReleaseComObject(host); }
Assembly[] assemblies; foreach (AppDomain app in appDomains) { Console.WriteLine(app.FriendlyName);
assemblies = app.GetAssemblies();
Console.WriteLine("-----------------------Assemblies------------------"); foreach (Assembly assem in assemblies) { Console.WriteLine(assem.FullName); } Console.WriteLine("---------------------------------------------------"); }
}
|