使用C#进行内存转储
我有一个System.Diagnostics.Process
对象。 我的C#程序正在监视某些情况。 当条件被命中时,我想要获取进程的完整内存转储。
实现这一目标的最佳方法是什么?
有没有CLR提供的方法?
你可以使用来自Sysinternals的ProcDump并让你的C#程序在需要时调用它。
Process.Start("procdump " + otherProgramPID.ToString());
您可以尝试从C#代码中调用C ++方法。 这是一个如何声明它的例子:
[DllImport("dbghelp.dll", EntryPoint = "MiniDumpWriteDump", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MiniDumpWriteDump( IntPtr hProcess, uint processId, SafeHandle hFile, MINIDUMP_TYPE dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam);
您可以查看该项目的代码示例: https : //github.com/projectkudu/kudu/blob/master/Kudu.Core/Infrastructure/MiniDumpNativeMethods.cs https://github.com/projectkudu/kudu/ BLOB / 2db563be679bb60656050ec3f04945086f07b360 / Kudu.Core /基础设施/ ProcessExtensions.cs