获取CLR ID [英] Getting the CLR ID

查看:178
本文介绍了获取CLR ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有哪里得到的CLR ID在运行当前应用程序?我使用监控高性能显示器我的系统,并用于实例的名称:

Is there any where to get the CLR ID at runtime for the current application? I am monitoring my system using Performance Monitors and the name used for the instance is:

ApplicationName.exe_p4952_r15_ad1

我可以得到所有其他参数编程,而不是 R15 这是一个执行代码公共语言运行库(实例)的运行ID。我注意到它始终是15,但最好是把它动态地避免并发症的发生。

I can get all other parameters programmatically but not the r15 which is the runtime ID of the common language runtime (instance) that executes your code. I noticed it is always 15, but it is best to get it dynamically to avoid complications.

推荐答案

您可以得到整个后缀,即部分之后 Application.exe 使用相同的基础设施。NET框架(如peformance柜)一样。

You can get the whole "suffix", i.e. the part after Application.exe using the same infrastructure that the .NET framework (e.g. the peformance counters) does.

有是方法系统。 Runtime.Versioning.VersioningHelper.MakeVersionSafeName ,它可以做到这一点。注意,这个方法被描述为基础设施和此API支持.NET Framework基础结构,不适合直接在代码中使用。,但仍然是公开的。我不认为有任何更好的支持的方式得到你想要的信息。至少它是更强大的和有弹性的未来的变化,然后反向工程基于文档的信息。

There is the method System.Runtime.Versioning.VersioningHelper.MakeVersionSafeName, which can do that. Note that the method is described as being "Infrastructure" and "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", but nevertheless is public. I don't think there is any "better supported" way to get the information you want. At least it is more robust and resilient to future changes, then reverse engineering the information based on documentation.

string suffix = System.Runtime.Versioning.VersioningHelper.MakeVersionSafeName("",                         
    System.Runtime.Versioning.ResourceScope.Machine,
    System.Runtime.Versioning.ResourceScope.AppDomain));

这将返回 _p4472_r16_ad1 ,例如

当然,你也可以直接通过性能计数器的基本名称,直接获得全名。上述空字符串的使用只是一招,只得到了后缀。

Of course, you could also directly pass the basename of the performance counter to directly get the full name. The usage of the empty string above is only a trick to just get the "suffix".

string str = VersioningHelper.MakeVersionSafeName("Application.exe",
    ResourceScope.Machine, ResourceScope.AppDomain);

// str -> "Application.exe_p4472_r16_ad1".



VersioningHelpers 也有私有方法 GetRuntimeId(),但鉴于以上情况,我不认为这里有必要使用上反射达到你所需要的。

The class VersioningHelpers also has the private method GetRuntimeId(), but given the above, I don't think it is neccessary to use reflection on that achieve what you need.

这篇关于获取CLR ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆