Last active
June 28, 2017 09:51
-
-
Save Criteo-dotnet-blog/911cc25f3c43caaba6317afff5a523c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static ulong GetTaskStateFromAddress(ulong address) | |
| { | |
| var type = Runtime.GetHeap().GetObjectType(address); | |
| if ((type != null) && (type.Name.StartsWith("System.Threading.Task"))) | |
| { | |
| // try to get the m_stateFlags field value | |
| ClrInstanceField field = type.GetFieldByName("m_stateFlags"); | |
| if (field != null) | |
| { | |
| var val = field.GetValue(address); | |
| if (val != null) | |
| { | |
| try | |
| { | |
| return (ulong)(int)val; | |
| } | |
| catch (InvalidCastException) | |
| { | |
| } | |
| } | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment