473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

How to enumerate AppDomains in current process

750 Expert 512MB
Here is a code i found on "how to enumerate appdomains in a current process".
The original code was posted by Thomas Scheidegger


Add the following as a COM reference - ~\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscor ee.tlb

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

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mountain Bikn' Guy | last post by:
I need some advice on this. I am working on a fairly complex calculator app (C#) with lots of functions (and these functions in turn use math functions from an unmanaged C DLL). A calculation takes...
6
by: Pete Davis | last post by:
I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app,...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
1
by: billr | last post by:
hi there, I hope that someone will be able to shed some light on little old confused me. We are developing an application which will be deployed onto a Terminal Server machine. The application...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
1
by: Maxwell2006 | last post by:
Hi, How can I get a list of AppDomains under the current process? Thank you,
0
by: kayakyakr | last post by:
I'm working with a set of experiments in a large system that is using AppDomains for isolation and wants to make a call out to an umanaged dll. The test dll has two methods, SetNumber(int num) and...
3
by: | last post by:
If this is simple, forgive my ignorance, but I'm coming from the CompactFramework where we don't use AppDomains. I did a fair bit of archive searching and couldn't find an answer and I got no...
0
by: jeremyje | last post by:
I would like to create an application where I have many concurrent processes being managed by a monitoring process. Each process that is "managed" will be invoked from an assembly dll (think...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.