472,784 Members | 992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 472,784 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 8408

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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.