Created
November 13, 2018 10:19
-
-
Save Criteo-dotnet-blog/e8541eb99372e92d747875a86d4baf0a to your computer and use it in GitHub Desktop.
This file contains 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 Type _processInfoType = null; | |
private static FieldInfo _processNameField = null; | |
public static string GetProcessNameByReflection(Process p) | |
{ | |
var processInfoField = typeof(System.Diagnostics.Process) | |
.GetField("processInfo", BindingFlags.Instance | BindingFlags.NonPublic); | |
var processInfo = processInfoField.GetValue(p); | |
if (_processInfoType == null) | |
{ | |
_processInfoType = processInfo.GetType(); | |
_processNameField = _processInfoType.GetField("processName"); | |
} | |
return _processNameField.GetValue(processInfo).ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment