/// <summary> /// Dumps an application minidump of the current process to the provided stream. /// </summary> /// <param name="stream">The stream to write the minidump to.</param> public static void Dump(FileStream stream) { //Store the exception information NativeMethods.MiniDumpExceptionInfo exception = new NativeMethods.MiniDumpExceptionInfo() { ClientPointers = false, ExceptionPointers = Marshal.GetExceptionPointers(), ThreadId = (uint)System.Threading.Thread.CurrentThread.ManagedThreadId }; NativeMethods.MiniDumpWriteDump(Process.GetCurrentProcess().Handle, (uint)Process.GetCurrentProcess().Id, stream.SafeFileHandle, NativeMethods.MiniDumpType.MiniDumpWithFullMemory, ref exception, IntPtr.Zero, IntPtr.Zero); }
private void WriteMemoryDump(string dumpFolder, Exception e) { using (FileStream stream = new FileStream(Path.Combine(dumpFolder, MemoryDumpFileName), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { NativeMethods.MiniDumpExceptionInfo exception = new NativeMethods.MiniDumpExceptionInfo(); exception.ClientPointers = false; exception.ExceptionPointers = Marshal.GetExceptionPointers(); exception.ThreadId = (uint)AppDomain.GetCurrentThreadId(); NativeMethods.MiniDumpWriteDump(Process.GetCurrentProcess().Handle, (uint)Process.GetCurrentProcess().Id, stream.SafeFileHandle, NativeMethods.MiniDumpType.MiniDumpWithFullMemory, ref exception, IntPtr.Zero, IntPtr.Zero); } }