PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 5:51 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Feb 23, 2015 10:06 am 
Offline

Joined: Tue Jan 13, 2015 3:33 pm
Posts: 10
Hello,

when I try to create a PDF in an asynchronous Task I get the following Exception:

Code:
Der Thread wurde abgebrochen.
   bei Microsoft.Win32.Win32Native.WriteFile(SafeFileHandle handle, Byte* bytes, Int32 numBytesToWrite, Int32& numBytesWritten, IntPtr mustBeZero)
   bei System.IO.FileStream.WriteFileNative(SafeFileHandle handle, Byte[] bytes, Int32 offset, Int32 count, NativeOverlapped* overlapped, Int32& hr)
   bei System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
   bei System.IO.FileStream.FlushInternalBuffer()
   bei System.IO.FileStream.Flush(Boolean flushToDisk)
   bei System.IO.FileStream.Flush()
   bei System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   bei System.IO.StreamWriter.Flush()
   bei MigraDoc.DocumentObjectModel.Serializer.get_Position()
   bei MigraDoc.DocumentObjectModel.Serializer.BeginBlock()
   bei MigraDoc.DocumentObjectModel.Serializer.BeginContent()
   bei MigraDoc.DocumentObjectModel.Tables.Cell.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Tables.Cells.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Tables.Row.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Tables.Rows.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Tables.Table.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.DocumentElements.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Section.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Sections.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.Document.Serialize(Serializer serializer)
   bei MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteDocument(DocumentObject documentObject)
   bei MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(DocumentObject docObject, String filename, Int32 indent, Int32 initialIndent)
   bei MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(DocumentObject docObject, String filename)


What I call is:

Code:
Task t = Task.Factory.StartNew(
      c =>
      {
        try
        {
           //generates the pdf and calls the function that throws the Exception
          sendPdfReport((HttpContext)c);
        }
        catch (Exception e)
        {
          //Do something in case of Exception
        }
      }, HttpContext.Current);


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 23, 2015 10:37 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

The call stack shows "DdlWriter.WriteToFile". Are you sure you're creating a PDF file, not an MDDDL file?
Maybe there is some debug code that creates an MDDDL file.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 23, 2015 12:51 pm 
Offline

Joined: Tue Jan 13, 2015 3:33 pm
Posts: 10
Hi,

as I took from the examples, first I create a MDDDL file then I create the pdf.
Isn't it necessary to create the MDDDL?


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 23, 2015 1:54 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
D_F_G wrote:
Isn't it necessary to create the MDDDL?
This step is not necessary.
Our application creates MDDDL files in DEBUG mode as it might help if the resulting document does not look as expected, but in RELEASE build we never create them.
We'll make this clearer in the samples when we revise them.

The exception occurs during file IO - and creation of the PDF also requires file IO, so the same exception may occur.
You can use a memory stream to create the PDF "file".

Is there a critical race maybe? Task still running while HttpContext was already disposed or something like that?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 350 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group