[Mono-dev] Getting the list of all AppDomains in a process

Lionel Cuir lionel_email at aulofee.com
Fri Feb 12 03:44:44 EST 2010


Hi All,
 
I need to get a list of all loaded AppDomains in the running process
(without asking developer to explicitely register them in a static hashtable
for instance). In .NET on Windows, I can use COM Interop (see code below).
But this is of course unlikely to run in Mono/Linux. Does anybody know how
to do? 
 
Zoltan, I've read in http://www.mono-project.com/Todo that there would be a
"appdomain ID-indexed tables " => can it be used for this? Where is it?
 
thks in advance for your ideas
 
Lionel
 
 
 
Code to do this with COM Interop on Windows (coming from
http://weblogs.asp.net/nunitaddin/archive/2003/02/07/1992.aspx):
 

// Add the following as a COM reference...

// C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\mscoree.tlb





using System;

using System.Collections;

using System.Runtime.InteropServices;

using mscoree;


public class AppDomainUtils

{

    public static IList ListAppDomains()

    {

        CorRuntimeHostClass host = new CorRuntimeHostClass();

        try

        {

            ArrayList list = new ArrayList();

            IntPtr enumHandle;



            host.EnumDomains(out enumHandle);

            while(true) 

            {

                object domain;

                host.NextDomain(enumHandle, out domain);

                if(domain == null) break;

                list.Add((AppDomain)domain);

            }

            host.CloseEnum(enumHandle);

            return list;

        }

        finally

        {

            Marshal.ReleaseComObject(host);

        }

    }

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100212/a3cbd3bb/attachment.html 


More information about the Mono-devel-list mailing list