473,382 Members | 1,464 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,382 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 8625

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.