Getting the CLR ID

后端 未结 3 1756
温柔的废话
温柔的废话 2021-01-17 18:53

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:

3条回答
  •  猫巷女王i
    2021-01-17 19:44

    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.

提交回复
热议问题