using System; using System.Reflection; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.IO; using System.Threading; using System.Globalization; using System.Diagnostics; using System.Collections.Generic; public class CallMyHelloWorld { public static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomainUnhandledException); string i; i = Console.ReadLine(); int a = Convert.ToInt32(i); int j = 10 / a; Console.WriteLine("The Application succeeded"); } public static class MINIDUMPTYPE { public const int MiniDumpNormal = 0x00000000; public const int MiniDumpWithDataSegs = 0x00000001; public const int MiniDumpWithFullMemory = 0x00000002; public const int MiniDumpWithHandleData = 0x00000004; public const int MiniDumpFilterMemory = 0x00000008; public const int MiniDumpScanMemory = 0x00000010; public const int MiniDumpWithUnloadedModules = 0x00000020; public const int MiniDumpWithIndirectlyReferencedMemory = 0x00000040; public const int MiniDumpFilterModulePaths = 0x00000080; public const int MiniDumpWithProcessThreadData = 0x00000100; public const int MiniDumpWithPrivateReadWriteMemory = 0x00000200; public const int MiniDumpWithoutOptionalData = 0x00000400; public const int MiniDumpWithFullMemoryInfo = 0x00000800; public const int MiniDumpWithThreadInfo = 0x00001000; public const int MiniDumpWithCodeSegs = 0x00002000; } [DllImport("dbghelp.dll")] public static extern bool MiniDumpWriteDump(IntPtr hProcess, Int32 ProcessId, IntPtr hFile, int DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallackParam); private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e) { CreateMiniDump(); } private static void CreateMiniDump() { DateTime endTime = DateTime.Now; string dt = endTime.ToString("yyyy.MM.dd.HH.mm.ss", DateTimeFormatInfo.InvariantInfo); System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("Test_app"); string dumpFileName = "C:\\HelloWorldDump" + process[0] + dt + ".dmp"; FileStream fs = new FileStream(dumpFileName, FileMode.Create); MiniDumpWriteDump(process[0].Handle, process[0].Id, fs.SafeFileHandle.DangerousGetHandle(), MINIDUMPTYPE.MiniDumpWithFullMemory, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)