Code block freezing and not throwing exception

6

I am using the twain library for scanner, and the application lists some devices that when selecting does not work, so I debugged and saw that it does not throw the exception that I treated, but it freezes in that code

 public void Acquire()
    {
        TwRC rc;
        CloseSrc();
        if (appid.Id == IntPtr.Zero)
        {
            Init(hwnd);
            if (appid.Id == IntPtr.Zero)
                return;
        }
        try
        {
            //CONGELA NESSE BLOCO ABAIXO E NÂO LANÇA EXCEPTION
            rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds);
        }
        catch(Exception ex)
        {
            throw new ScannerException("Não foi possivel digitalizar, verifique o driver selecionado!");
        }
        TwCapability cap = new TwCapability(TwCap.XferCount, 1);
        rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);
        if (rc != TwRC.Success)
        {
            CloseSrc();
            throw new ScannerErroDigitalizarException("Erro ao carregar driver selecionado. Verifique se o driver pertence a um Scanner.");
        }

        TwUserInterface guif = new TwUserInterface();
        guif.ShowUI = 1;
        guif.ModalUI = 1;
        guif.ParentHand = hwnd;
        rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif);
        if (rc != TwRC.Success)
        {
            CloseSrc();
            throw new ScannerErroDigitalizarException("Erro ao carregar driver selecionado. Verifique se o driver pertence a um Scanner.");
        }
    }

How to treat the same?

Reference: link

    
asked by anonymous 12.07.2015 / 14:42

1 answer

4

It may be that the code is locking in some internal library exception, but it does not show the error because that exception is handled by the library itself or because it is waiting for some response from an external component (the scanner, for example ).

To cause Visual Studio to stop at these internal exceptions, do the following:

  • While you are debugging the application, open the Exceptions window through the Debug -> menu. Exceptions ... or keyboard shortcut CTRL + D + E .
  • In the Exceptions window, check some or all of the checkboxes in the Thrown column.

  • Simulate your functionality again. If the reason for the freeze is really an internal exception, Visual Studio will stop at each of these exceptions giving you an opportunity to get more information about the error.

  • I suggest that you review the message and further details of each of these internal exceptions that may occur in the block of code that is freezing. One of them will give you the correct direction to solve the actual problem that is occurring.

        
    15.07.2015 / 13:27