Beispiel #1
0
        void captureWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            CaptureArguments captureArguments = (CaptureArguments)e.Argument;

            using (FileStream crashDumpFileStream = File.Create(captureArguments.FilePath))
            {
                bool success = MiniDumpFile.Create(
                    captureArguments.ProcessHandle,
                    (uint)captureArguments.ProcessId,
                    crashDumpFileStream.SafeFileHandle,
                    captureArguments.MiniDumpType,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero);

                if (!success)
                {
                    int lastError = Marshal.GetLastWin32Error();

                    // Neat way to avoid the pain of calling FormatMessage.
                    // You can create a new instance of Win32Exception without calling GetLast*Error first,
                    // but I prefer this way as it's more obvious what's happening
                    Win32Exception lastErrorException = new Win32Exception(lastError);

                    MessageBox.Show(lastErrorException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }