Exemplo n.º 1
0
        public static IList <AppDomain> GetAppDomains()
        {
            IList <AppDomain> _IList     = new List <AppDomain>();
            IntPtr            enumHandle = IntPtr.Zero;
            CorRuntimeHost    host       = new mscoree.CorRuntimeHost();

            try
            {
                host.EnumDomains(out enumHandle);
                object domain = null;
                while (true)
                {
                    host.NextDomain(enumHandle, out domain);
                    if (domain == null)
                    {
                        break;
                    }
                    AppDomain appDomain = (AppDomain)domain;
                    _IList.Add(appDomain);
                }
                return(_IList);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
            finally
            {
                host.CloseEnum(enumHandle);
                Marshal.ReleaseComObject(host);
            }
        }
Exemplo n.º 2
0
        public IEnumerable <string> Get()
        {
            string[] domainNames = new string[10];
            int      ii          = 0;

            ICorRuntimeHost host       = null;
            IntPtr          enumHandle = IntPtr.Zero;

            try
            {
                host = new mscoree.CorRuntimeHost();
                host.EnumDomains(out enumHandle);
                object domain = null;

                host.NextDomain(enumHandle, out domain);
                while (domain != null && ii < 10)
                {
                    AppDomain ad = (AppDomain)domain;
                    domainNames[ii++] = ad.FriendlyName;
                    host.NextDomain(enumHandle, out domain);
                }
            }
            finally
            {
                if (host != null)
                {
                    if (enumHandle != IntPtr.Zero)
                    {
                        host.CloseEnum(enumHandle);
                    }

                    Marshal.ReleaseComObject(host);
                }
            }

            return(domainNames);
        }