无法获取与.NET Framework 4.0 Process相关的应用程序域的数据 [英] Not able to fetch data for Application Domains related to .NET Framework 4.0 Process
问题描述
我们要枚举特定计算机上的所有.NET Framework 4.0进程.然后要枚举这些进程的应用程序域.
We want to enumerate all .NET Framework 4.0 Processes on a particular machine. And then want to enumerate Application Domains for those processes.
枚举应用程序域后,我们希望使用以下API来获取有关每个应用程序域的数据.
After enumerating Application Domains, we want to fetch data about each Application Domain using following APIs.
ICLRAppDomainResourceMonitor :: GetCurrentAllocated 跨度>
ICLRAppDomainResourceMonitor :: GetCurrentSurvived
ICLRAppDomainResourceMonitor::GetCurrentSurvived
我们使用ICorPublishAppDomain接口以及以下代码进行了尝试:
We tried this using ICorPublishAppDomain Interface as well as following code :
ICLRMetaHost *meta;
ICLRRuntimeInfo *info;
ICLRRuntimeHost *host;
ICLRControl *control;
ICLRAppDomainResourceMonitor *monitor;
CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (void **)&meta);
meta->GetRuntime(L"v4.0.30319", IID_CLRRuntimeInfo, (void **)&runtime);
info->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (void **)&host);
host->GetCLRControl(&control);
control->GetCLRManager(IID_ICLRAppDomainResourceMonitor, (void **)&monitor);
// ... rest of CLR startup ...
unsigned long long bytes;
monitor->GetCurrentAllocated(1, &bytes);
但是,我们无法枚举系统上每个.NET Framework 4.0进程的应用程序域.
However, we couldnt enumerate App Domains for each .NET Framework 4.0 process on a system.
任何人都可以帮助我吗?非常感谢.
推荐答案
嗨奥迪,
令人惊讶的是,BCL中没有可管理的API来显示AppDomains L 使用 但是,互操作性可以列出AppDomain:
Surprisingly there is no managed API in the BCL to show AppDomains L Using Interop however, we can list the AppDomains:
using System.Runtime.InteropServices; // for domain enum
using mscoree; // for domain enum. Add the following as a COM reference - C:\WINDOWS\Microsoft.NET\Framework\vXXXXXX\mscoree.tlb
namespace MyNS
{
public class ListProcessAppDomains
{
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)
{
Console.WriteLine(e.ToString());
return null;
}
finally
{
host.CloseEnum(enumHandle);
Marshal.ReleaseComObject(host);
}
}
}
这篇关于无法获取与.NET Framework 4.0 Process相关的应用程序域的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!