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:
You can find it easily by splitting the string you get :
This function split the instance name , and search for the only part that begins with "r" and does not end with ".exe". Once the right part of the string has been found , just delete the first letter "r" and just keep the number to convert it into an integer number and return it. If the CLR ID is not found , just return "-1" to let the parent function notice this.
int getClrID(string instance_name)
{
string[] instance_name_parts = instance_name.Split('_');
string clr_id = "";
for (int i = 0; i < instance_name_parts.Length; i++)
{
if (instance_name_parts[i].StartsWith("r") && !instance_name_parts[i].EndsWith(".exe"))
{
clr_id = instance_name_parts[i];
break;
}
}
if (clr_id == "") // An error occured ...
return -1;
else
return Convert.ToInt32(clr_id.Substring(1));
}
I hope I helped you.