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);