跟踪Winform中的崩溃

时间:2015-10-06 20:04:13

标签: c# winforms

我正在编写一台批处理打印机,但它在打印期间随机崩溃,说“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;
            }
        }
    }

2 个答案:

答案 0 :(得分:1)

尝试查看系统的事件查看器。通常,如果你为.NET应用程序“xxx停止工作”,你会发现一些东西。

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

答案 1 :(得分:0)

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

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