Problem with get Pdf text (Thread Safe)

Discussions about PDF management.
Post Reply
alisson
Posts: 5
Joined: Mon Mar 07, 2016 9:51 pm

Problem with get Pdf text (Thread Safe)

Post by alisson » Tue Mar 22, 2016 10:17 pm

Hello,

I have this application that get's the PDF text when an user does an upload of some PDF files.
The problem is that my application throw an message error on Event Viewer, and, after that, close yourself.

Can you help me?
Is that an problem with GdPicture?
Look the EventViewer, have some internal methods from GdPicture.

Bellow, you have the code that gets the pdf text:

Code: Select all

     public string GetPlainTextFromPDF(byte[] value)
        {
            statusPlainTextPDF = 2; //sucesso
            MemoryStream stream = new MemoryStream(value);
            GdPicture12.GdPicturePDF pdf = new GdPicture12.GdPicturePDF();
            try
            {
                pdf.LoadFromStream(stream);

                string text = "";
                for (int i = 1; i <= pdf.GetPageCount(); i++)
                {
                    pdf.SelectPage(i);
                    text += pdf.GetPageText() + "\n";
                }

                pdf.LoadFromStream(null);
                return text;
            }
            catch (Exception e)
            {
                statusPlainTextPDF = 9; //erro no processamento
                logger.LogException(e);
                return "";
            }
            finally
            {
                stream.Close();
                stream.Dispose();
                pdf.Dispose();
            }
        }

And the Event Viewer log:

Nome do Log: Application
Fonte: ASP.NET 4.0.30319.0
Data: 14/03/2016 15:27:55
Identificação do Evento:1325
Categoria da Tarefa:Nenhum
Nível: Erro
Palavras-chave:Clássico
Usuário: N/D
Computador: WB8SSP20A.SISDPVATSIN.CORP
Descrição:
An unhandled exception occurred and the process was terminated.

Application ID: Domain 12

Process ID: 6052

Exception: System.ComponentModel.Win32Exception

Message: The operation completed successfully

StackTrace: at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height,

String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Threading.Dispatcher..ctor()
at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
at System.Windows.Media.Imaging.BitmapPalette..ctor(IList`1 colors)
at gdpicture_᝞.gdpicture_ᜀ()
at gdpicture_᝞.ᜀ.gdpicture_ᜀ()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object

state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state,

Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
XML de Evento:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="ASP.NET 4.0.30319.0" />
<EventID Qualifiers="49152">1325</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2016-03-14T18:27:55.000000000Z" />
<EventRecordID>261808</EventRecordID>
<Channel>Application</Channel>
<Computer>WB8SSP20A.SISDPVATSIN.CORP</Computer>
<Security />
</System>
<EventData>
<Data>An unhandled exception occurred and the process was terminated.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Problem with get Pdf text (Thread Safe)

Post by Loïc » Fri Mar 25, 2016 11:21 am

Hello Alisson,

Could you please check that you are using our latest available release? We''ve fixed a similar threading issue recently.

With best regards,

Loïc

alisson
Posts: 5
Joined: Mon Mar 07, 2016 9:51 pm

Re: Problem with get Pdf text (Thread Safe)

Post by alisson » Fri Apr 01, 2016 5:06 pm

Thank you Loïc, for reply.
I noticed that i was using the 12.0.0.2 version.
Today i have downloaded the 12.0.0.7 and i will try it.

alisson
Posts: 5
Joined: Mon Mar 07, 2016 9:51 pm

Re: Problem with get Pdf text (Thread Safe)

Post by alisson » Mon Jul 04, 2016 9:28 pm

Hello

Loïc, the problem with thread safe was solved (i put an semaphore on the code, to to wait the execution if another thread try to execute the same code)
But, another problem appeared. Can you help me?

We are using the 12.0.0.19 version, and i noticed that the GdPicture crashes my software, and logged an error on the eventviewer:

Here is my function:

Code: Select all

public string GetPlainTextFromPDF(byte[] value, ref int statusPlainTextPDF)
        {
            statusPlainTextPDF = 2; //sucesso
            MemoryStream stream = new MemoryStream(value);
            //The lock handler, to block the process with another thread
            EventWaitHandle lockHandle = new EventWaitHandle(true, EventResetMode.AutoReset, "{49C21F24-4FC7-4C69-8B88-C08E467F49D5}");
            lockHandle.WaitOne();
            GdPicture12.GdPicturePDF pdf = null;
            try
            {
                pdf = new GdPicture12.GdPicturePDF();
                pdf.LoadFromStream(stream);

                string text = "";
                for (int i = 1; i <= pdf.GetPageCount(); i++)
                {
                    pdf.SelectPage(i);
                    text += pdf.GetPageText() + "\n";
                }
                return text;
            }
            catch (Exception e)
            {
                statusPlainTextPDF = 9; //erro no processamento
                logger.LogException(e);
                return "";
            }
            finally
            {
                stream.Close();
                stream.Dispose();
                stream = null;
                if (pdf != null)
                {
                    pdf.Dispose();
                    pdf = null;
                }
                lockHandle.Set();
            }
        }
And bellow, the event viewer log:

Code: Select all

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
   at System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.Dispatcher.ShutdownImpl()
   at System.Windows.Threading.Dispatcher.StartShutdownImpl()
   at System.Windows.Threading.Dispatcher.ShutdownCallbackInternal()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at System.Windows.Threading.Dispatcher.CriticalInvokeShutdown()
   at gdpicture_ᝍ+ᜀ.gdpicture_ᜀ()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()


In another event log, i saw this log:
In Brazilian Portuguese:
Caminho do módulo com falha: C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\ea8ed7c2aaeeb0be15a74d75338c4c05\WindowsBase.ni.dll

In english:
Path with module with error: C:\Windows\assembly\NativeImages_v4.0.30319_32\WindowsBase\ea8ed7c2aaeeb0be15a74d75338c4c05\WindowsBase.ni.dll

I hope that you can help me.

Att,

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Problem with get Pdf text (Thread Safe)

Post by Loïc » Sun Jul 10, 2016 7:54 pm

Hi Alisson,

Are you able to reproduce the issue in a standalone application that you can share wit us?
If yes, please open a ticket into our helpdesk here: https://www.gdpicture.com/support/getting-support-from-our-team

With best regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest