【问题标题】:Tracking Crash in Winform在 Winform 中跟踪崩溃
【发布时间】:2015-10-06 20:04:13
【问题描述】:

我正在编写批处理打印机,但它在打印过程中随机崩溃,说“XXX已停止工作”,仅此而已。如何跟踪崩溃并获取更多信息?

我添加了trycatch,但它永远不会抓住括号。

代码:

    private void btnPrint_Click(object sender, EventArgs e)
    {
        if (parts == null)
        {
            return;
        }
        ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode);
        foreach (Part part in parts)
        {
            if (part.Selected)
            {
                switch (part.FileType)
                {
                    case "PDF":
                        //SendToPDFReaderPrinter(part);
                        break;
                    case "SLDDRW":
                        if (!useSolidworksToPrint)
                        {
                            SendToeDrawingsPrinter(part);
                        }
                        else
                        {
                            //SendToSolidworksPrinter(part);
                        }
                        break;
                }
            }
        }
        MessageBox.Show("Print Complete.");
    }

    private void SendToeDrawingsPrinter(Part part)
    {
        try
        {
            string filePath = part.FilePath;
            //Show Preview
            axAcroPDF1.Hide();
            eDrawingControl1.Show();
            //Load file
            eDrawingControl1.eDrawingControlWrapper.OpenDoc(filePath, false, false, false, "");
            //Config
            eDrawingControl1.eDrawingControlWrapper.SetPageSetupOptions(EModelView.EMVPrintOrientation.eLandscape, 1, 0, 0, 1, 7, printerName, 1, 1, 1, 1);
            //Print  
            Wait(2);  //Wait for 2 seconds
            eDrawingControl1.eDrawingControlWrapper.Print4(false, filePath, false, false, true, EModelView.EMVPrintType.eScaleToFit, 1, 0, 0, true, 1, 1);
            Wait(2);  //Wait for 2 seconds
            //eDrawingControl1.eDrawingControlWrapper.CloseActiveDoc("");
            //Hightligh Printed Row
            HighlightPrintedRow(part, true);
        }
        catch
        {
            HighlightPrintedRow(part, false);
        }
    }

    //Wait
    private void Wait(double seconds)
    {
        DateTime start = DateTime.Now;
        while (start.AddSeconds(seconds) >= DateTime.Now)
        {
            System.Windows.Forms.Application.DoEvents();
        }
    }

    private void HighlightPrintedRow(Part part, bool isSuccessful)
    {
        foreach (var row in ultraGrid1.Rows)
        {
            if ((Part)row.ListObject == part)
            {
                row.Appearance.BackColor = (isSuccessful ? Color.LightGreen : Color.Red);
                break;
            }
        }
    }

【问题讨论】:

  • 在调试器下运行时会出现这种情况吗?是否将其设置为在抛出异常时停止?
  • 你有没有逐步缩小它发生的范围?
  • 谢谢,我会尝试启用“抛出异常时中断”@RowlandShaw
  • 单步执行时没有任何问题...@DonBoitnott
  • .NET 的目标版本是什么?对于 .NET 4+,CLR 不允许进程处理 corrupted state exceptions。这可能是非托管代码引发的异常:在您的项目属性中启用非托管代码调试。此外,如果您包含HighlightPrintedRow 的代码,您可以帮助我们帮助您。

标签: c# winforms


【解决方案1】:

尝试查看系统的事件查看器。通常,如果您收到 .NET 应用程序的“xxx 停止工作”,您会在那里找到一些东西。

或者,您可以使用低级错误跟踪组件来捕获所有异常,即使是来自 .NET 运行时。见BugTrap

【讨论】:

  • 错误应用程序名称:bruno_batchprint.vshost.exe,版本:12.0.21005.1,时间戳:0x524fac12 错误模块名称:EModelView.dll,版本:15.0.0.5013,时间戳:0x5429b603 异常代码:0xc0000005错误偏移:0x00000000000a9c68 错误进程 id:0x2b84 错误应用程序启动时间:0x01d1007ba16d0b38 错误应用程序路径:D:\Projects\brumo_batch_print_excel\bruno_batchprint\bin\Debug\bruno_batchprint.vshost.exe 错误模块路径:C:\Program Files\SOLIDWORKS Corp\ eDrawings X64 Edition\EModelView.dll 报告 ID:f2556ebe-6c70-11e5-b85d-c0389642987a
  • 我猜这意味着错误发生在“EModelView.dll”中?怎么知道是dll内部错误还是我使用不当造成的?
  • 是的,这是该组件的故障。您可能需要询问该组件的支持团队。或者你仍然可以尝试使用 BugTrap,看看它是否能告诉你更多细节。
【解决方案2】:

试试这个Switching to Managed Compatibility Mode in Visual Studio 2013

有时 VS 重启或重启会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2018-05-08
    • 2015-09-01
    • 2019-03-19
    • 1970-01-01
    相关资源
    最近更新 更多