Taking memory dump using C#

后端 未结 3 1918
孤独总比滥情好
孤独总比滥情好 2021-02-04 00:15

I\'ve got a System.Diagnostics.Process object. My C# program is monitoring it for some condition. When the condition is hit, I want to take a full memory d

3条回答
  •  自闭症患者
    2021-02-04 01:02

    You can try calling the C++ method from your C# code. Here's an example of how you would declare it:

        [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);
    

    You can check out the code of this project for an example: https://github.com/projectkudu/kudu/blob/master/Kudu.Core/Infrastructure/MiniDumpNativeMethods.cs https://github.com/projectkudu/kudu/blob/2db563be679bb60656050ec3f04945086f07b360/Kudu.Core/Infrastructure/ProcessExtensions.cs

提交回复
热议问题