Пример #1
0
		// based on the code from http://blogs.msdn.com/b/jackg/archive/2007/06/11/enumerating-appdomains.aspx
		public static List<AppDomain> get_AppDomains_in_CurrentProcess(this API_Mscoree mscoree)
		{
			var corRuntimeHostClass = new mscoree.CorRuntimeHostClass();
			var  _IList = new List<AppDomain>();
			IntPtr enumHandle = IntPtr.Zero;
			CorRuntimeHostClass host = new mscoree.CorRuntimeHostClass();
			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);
			}			
		}
Пример #2
0
        // based on the code from http://blogs.msdn.com/b/jackg/archive/2007/06/11/enumerating-appdomains.aspx
        public static List <AppDomain> get_AppDomains_in_CurrentProcess(this API_Mscoree mscoree)
        {
            var    corRuntimeHostClass = new mscoree.CorRuntimeHostClass();
            var    _IList            = new List <AppDomain>();
            IntPtr enumHandle        = IntPtr.Zero;
            CorRuntimeHostClass host = new mscoree.CorRuntimeHostClass();

            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);
            }
        }
        public static IList <AppDomain> GetAppDomains()
        {
            IList <AppDomain>   _IList     = new List <AppDomain>();
            IntPtr              enumHandle = IntPtr.Zero;
            CorRuntimeHostClass host       = new mscoree.CorRuntimeHostClass();

            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)
            {
                ExceptionLogger.LogException("GetAppDomains error", e);
                return(null);
            }
            finally
            {
                host.CloseEnum(enumHandle);
                Marshal.ReleaseComObject(host);
            }
        }