1

I'm programming a batch printer, but it crashes randomly during the print, saying "XXX has stop working", nothing more than that. How do I track the crash and get more information?

I added try and catch but it never goes to catch bracket.

Code:

    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;
            }
        }
    }
Brian
  • 53
  • 1
  • 11
  • 1
    Does that happen when running under the debugger? Do you set it to stop when exceptions are thrown? – Rowland Shaw Oct 06 '15 at 20:06
  • 1
    Have you stepped through to narrow down the line on which it occurs? – DonBoitnott Oct 06 '15 at 20:06
  • Thanks, I will try enabling "break when exceptions are thrown" @RowlandShaw – Brian Oct 06 '15 at 20:12
  • Nothing goes wrong when step through...@DonBoitnott – Brian Oct 06 '15 at 20:13
  • When I try to debug, no exception is thrown, I got a "vshost.exe" has sttpped working" error – Brian Oct 06 '15 at 20:23
  • Have you tried debugging to see which line the application stops working on? – John Odom Oct 06 '15 at 20:40
  • 1
    What is the target version of .NET? For .NET 4+ the CLR does not allow the process to handle [corrupted state exceptions](http://dotnetslackers.com/articles/net/All-about-Corrupted-State-Exceptions-in-NET4.aspx). This could be an exception thrown by unmanaged code: in your project properties enable unmanaged code debugging. Also, if you include the code for `HighlightPrintedRow` you may help us help you. – groverboy Oct 07 '15 at 01:45
  • If your error is tied to assembly loading error, it won't help much, but you could be interested by handling AppDomain.CurrentDomain.UnhandledException and Application.ThreadException events. See http://stackoverflow.com/questions/2770/global-exception-handling-for-winforms-control – AFract Oct 07 '15 at 14:23

2 Answers2

2

Try to have a look at the system's Event Viewer. Usually you will find something there if you get 'xxx stops working' for .NET applications.

Or, you can use a low-level bug tracking component to catch all exception even from the .NET runtime. See BugTrap

xtu
  • 417
  • 3
  • 12
  • Faulting application name: bruno_batchprint.vshost.exe, version: 12.0.21005.1, time stamp: 0x524fac12 Faulting module name: EModelView.dll, version: 15.0.0.5013, time stamp: 0x5429b603 Exception code: 0xc0000005 Fault offset: 0x00000000000a9c68 Faulting process id: 0x2b84 Faulting application start time: 0x01d1007ba16d0b38 Faulting application path: D:\Projects\brumo_batch_print_excel\bruno_batchprint\bin\Debug\bruno_batchprint.vshost.exe Faulting module path: C:\Program Files\SOLIDWORKS Corp\eDrawings X64 Edition\EModelView.dll Report Id: f2556ebe-6c70-11e5-b85d-c0389642987a – Brian Oct 07 '15 at 15:52
  • I guess this means the error occurs in "EModelView.dll" ? How do I know whether it is caused by the dll 's internal error or because I've used it in an improper way? – Brian Oct 07 '15 at 15:56
  • Yes, it is the fault from that component. You may need to ask the supporting team of that component. Or you can still try to use BugTrap and see if it can tell you more details. – xtu Oct 08 '15 at 16:26
1

Try this Switching to Managed Compatibility Mode in Visual Studio 2013

Sometimes a VS restart or reboot helps.

David J.
  • 64
  • 6