473,546 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to enumerate AppDomains in current process

750 Recognized Expert Contributor
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\Micro soft.NET\Framew ork\v2.0.50727\ mscoree.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 8666

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

Similar topics

4
2948
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 a lot of time (up to hours), and should run on a separate thread from the one that the GUI uses. The GUI also needs to display various properties...
6
4490
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, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone...
18
3143
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 question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the...
1
2548
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 will be used concurrently by multiple users. We have a static object (which as you well know is only static per AppDomain), -I think I've just...
6
4098
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 memory management and connection pooling constructs) as static variables which were intended to scoped to the process. 2. Managed C++ assemblies...
1
2201
by: Maxwell2006 | last post by:
Hi, How can I get a list of AppDomains under the current process? Thank you,
0
1586
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 GetNumber(), and a global variable. The DllImport and getting and setting the numbers are fine. The problem comes when I make the calls to the...
3
3745
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 responsed in the remoting group after a week, so I'm throwing a little wider net this time. I have a desktop app (FFx 2.0) developed with Studio 05...
0
1850
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 reflection). I want a way to invoke these processes in parallel utilizing multi-core processors but I'd like to have the protection that AppDomains...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.