public static extern bool MiniDumpWriteDump( PssSnapshotSafeHandle hpss, uint processId, SafeHandle hFile, MINIDUMP_TYPE dumpType, IntPtr expParam, IntPtr userStreamParam, [In] ref MINIDUMP_CALLBACK_INFORMATION callbackParam);
public static void SnapshotAndDump(this Process process, string dumpFile, MINIDUMP_TYPE dumpType) { using (var fs = new FileStream(dumpFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { using (var pssSnapshot = PssSnapshotSafeHandle.CaptureSnapshot(process.Handle)) { bool PssSnapshotMinidumpCallback(IntPtr unused, ref MINIDUMP_CALLBACK_INPUT input, ref MINIDUMP_CALLBACK_OUTPUT output) { const int S_OK = 0; const int S_FALSE = 1; switch (input.CallbackType) { case MINIDUMP_CALLBACK_TYPE.IsProcessSnapshotCallback: // The target is always a snapshot. output.Status = S_FALSE; break; case MINIDUMP_CALLBACK_TYPE.ReadMemoryFailureCallback: // Ignore any read failures during dump generation. output.Status = S_OK; break; } return(true); } var callbackParam = new MINIDUMP_CALLBACK_INFORMATION { CallbackParam = IntPtr.Zero, CallbackRoutine = PssSnapshotMinidumpCallback }; if (!MiniDumpWriteDump(pssSnapshot, (uint)process.Id, fs.SafeFileHandle, dumpType | MINIDUMP_TYPE.IgnoreInaccessibleMemory, IntPtr.Zero, IntPtr.Zero, ref callbackParam)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } } }
public static extern int PssCaptureSnapshot(IntPtr processHandle, PSS_CAPTURE_FLAGS captureFlags, uint threadContextFlags, out PssSnapshotSafeHandle snapshotHandle);