Code block freezing and does not release Exception

Asked

Viewed 303 times

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 launch the Exception I treated, and yes it freezes in this 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: http://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner

  • You need to put more code to give more context, say which exception, indicate library documentation.

  • Edited by @bigown ...

  • @Warlock, am I mistaken or do you first try to import the image before loading the drivers? I noticed that after Try...catch has the driver instructions and at the end the error "Error .... " will not be reversed?

  • @Warlock command has worked?

1 answer

4

It may be that the code is crashing on some internal library exception, but it does not show the error due to this exception being handled by the library itself or due to it waiting for some response from an external component (the scanner, for example).

To make Visual Studio stop in these internal exceptions, do the following:

  1. While debugging the application, open the window Exceptions through the menu Debug -> Exceptions... or keypad clutch CTRL + D + E.

inserir a descrição da imagem aqui

  1. In the Exceptions window, check some or all checkboxes in the column Thrown.

  2. Simulate its functionality again. If the reason for freezing 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 you analyze the message and other details of each of these internal exceptions that occur in the code block that is freezing. One of them will give you the right direction to solve the real problem that is occurring.

  • Thank you for trying to help me, I did this and appeared Accessviolationexception, error while trying to save memory not allowed. It is a dll that I do not have access to the code, what I want to do is play the message to the user saying that it was not possible... it is still freezing and closing the application.

  • Now we found the error! I searched here and there seems to be a solution. Please install this Hotfix https://support.microsoft.com/en-us/kb/971030 on the machine you are running the application on and try again. It addresses this issue of trying to access unauthorized memory.

  • Please excuse my ignorance but I couldn’t find the download link, could you pass me here?

  • Tranquil. I posted in the previous comment. This is the link => https://support.microsoft.com/en-us/kb/971030

  • I meant I didn’t find the download link inside that link you gave me

  • Oh yes. True, I looked at the page doesn’t really have the download link. What she says is that this Hotfix has been replaced by another, which solves some more problems than that of access to protected memory. The link to this new Hotfix is https://support.microsoft.com/en-us/kb/981574. But, the page says you need to contact microsoft support directly to get the Hotfix, via the page http://support.microsoft.com/contactus/? Ws=support. It seems that it will not be that simple. Until I get another answer I’ll try to get that Hotfix and if I can warn you.

  • Okay, I’ll wait, I’ll look too thank you.

  • @Warlock found a forum where they said they solved this problem by running the command netsh Winsock reset. Would this command also not work for this case?

  • 1

    @Warlock, am I mistaken or do you first try to import the image before loading the drivers? I noticed that after Try...catch has the driver instructions and at the end the error "Error .... " will not be reversed?

  • @Ulyssesalves where I execute this command?

  • @Warlock At the Windows command line. First open the Windows command prompt from the menu Start -> Run -> cmd. Then inside the command line window you type the command netsh Winsock reset and press the ENTER key on the keyboard. It is advisable that you open the command line as administrator. To do this, in the Start menu, type cmd and when the program icon appears right click on it and click "Run as administrator". In this article is more detailed http://en.m.wikihow.com/Open-o-Prompt-de-command-on-Windows

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.