Programmatically Generating a Dump File
I've discussed dump analysis on several occasions, including detailed walkthroughs of native and managed issues - crashes, hangs, deadlocks and the rest of the bug zoo.
(Alon has just recently been to this bug zoo and promised me pictures.)
Oftentimes it's useful to generate a dump programmatically. For example, if your application fails and you want to record the data and send it over the network or persist it to some durable storage, you can do so without relying on Windows Error Reporting or other mechanisms.
private static extern bool MiniDumpWriteDump(
[In] IntPtr hProcess,
[In] IntPtr ExceptionParam,
[In] IntPtr UserStreamParam,
[In] IntPtr CallbackParam);
The way to go is the MiniDumpWriteDump function, exposed from dbghelp.dll. I've written a simple helper class for using this API from C#, which can be downloaded from here. Sample usage would be:
Process process = Process.Start("notepad.exe");