Click here to Skip to main content
15,920,383 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

while debugging i got the error like this Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

This below error code line works for capture screen and do ocr. But dynamically(Means Multiple time capturing window with certain time limits) changing window capture and do ocr is giving error.

private void OCRImplementationall()
            MODI.Document md = new MODI.Document();

            Cursor = Cursors.WaitCursor;
            string Name = AppDomain.CurrentDomain.BaseDirectory + @"PT INFO.JPG";
                int fflag = 0;
                CheckForIllegalCrossThreadCalls = false;
                md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
                string strText = String.Empty;

                MODI.Image image = (MODI.Image)md.Images[0];
                MODI.Layout layout = image.Layout;
                string[] splvalues = layout.Text.Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                //for (int i = 0; i < layout.Words.Count; i++)
                int i = 0;
                foreach (string val in splvalues)
  catch (Exception ex)
               //ExceptionHelper exlne = new ExceptionHelper();

                LogFile(ex.Message, "OCRImplementationall", "PT INFO Image Error", ExceptionHelper.LineNumber(ex), this.FindForm().Name);

                Cursor = Cursors.Default;

May i know whats the issue i made here in this line
Updated 31-Jul-13 1:26am

Refer - Attempt to read or write Protected Memory This is often an indicating that other memory is corrupt[^].

The answer holds some explanation about the issue. You can also suppress this Exception.
Take a look, it might help you.
Share this answer
visnumca123 31-Jul-13 9:16am    

i done below steps

Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load"

Still its not working...
Did you see other details about what exactly is the issue and all?
From your desciption, I'd rather suspect that the library is not multithreading-proof. Hence you have to wait for the OCR processing to have finished before you start the next processing. That's a limitation of that library, and your code has to obey to those limitation.
Share this answer
visnumca123 1-Aug-13 10:32am    
I increased thread.sleep(5000) and i did the below
md = null;
but still i have the same issue!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900