/// <summary> /// Save memory dump on disk /// </summary> /// <param name="filePath">The path where the minidump file will be saved</param> /// <param name="options">Minidump save options</param> /// <param name="exceptionType">Type to check if exception exists</param> internal static bool Write(string filePath, MiniDumpType options = MiniDumpType.WithFullMemory, MinidumpException exceptionType = MinidumpException.None) { bool miniDumpAvailable = IsMemoryDumpAvailable(); if (!miniDumpAvailable) { return(false); } Process currentProcess = Process.GetCurrentProcess(); IntPtr currentProcessHandle = currentProcess.Handle; uint currentProcessId = (uint)currentProcess.Id; var exceptionInformation = MiniDumpExceptionInformation.GetInstance(exceptionType); using (FileStream fileHandle = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Write)) { return(exceptionInformation.ExceptionPointers == IntPtr.Zero ? MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle.SafeFileHandle, (uint)options, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) : MiniDumpWriteDump(currentProcessHandle, currentProcessId, fileHandle.SafeFileHandle, (uint)options, ref exceptionInformation, IntPtr.Zero, IntPtr.Zero)); } }
internal static extern bool MiniDumpWriteDump(IntPtr hProcess, uint processId, SafeHandle hFile, uint dumpType, ref MiniDumpExceptionInformation expParam, IntPtr userStreamParam, IntPtr callbackParam);