I have experienced problems when using spire with multi-threaded application.
the application has been running successfully as a single threaded application. As soon as the multi threading was implemented, spire has been throwing the following errors:
•Wrong dynamic huffman codes.
•Object reference not set to an instance of an object.
•Unknown block type. Stream might be corrupted.
•Zip exception.Can't find local header signature - wrong file format or file is corrupt.
•Zip exception.End of file reached - wrong file format or file is corrupt.
•Zip exception.Unable to read value at the specified position - end of stream was reached.
•Zip exception.Wrong Crc value.
If I put the call to for example LoadFromStream or SaveToStream within a lock statement everything works, indicating that the errors are somehow caused by lack of thread safety..?
For example, i have a function that converts a stream to pdf, when it is called by several threads, it throws the exceptions below :
- Code: Select all
public byte[] ConvertToPdf(byte[] content)
{
byte[] result = null;
CultureInfo cc = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
try
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Document doc = new Document();
using (MemoryStream str = new MemoryStream(content))
{
doc.LoadFromStream(str, FileFormat.Docx);
}
ToPdfParameterList topdfparams = new ToPdfParameterList();
topdfparams.IsEmbeddedAllFonts = true;
topdfparams.AutoFitTableLayout = true;
using (MemoryStream outstream = new MemoryStream())
{
doc.SaveToStream(outstream, topdfparams);
doc.Close();
result = outstream.ToArray();
}
return result;
}
catch (Exception ex)
{
throw new AsConfException("Can not generate pdf : " + ex.Message, "");
}
finally
{
Thread.CurrentThread.CurrentCulture = cc;
}
}
Any help with this would be much appreciated!