WPCubed Product Support

Thread Safe?

support

wPDFControl 4 comes with a new deme to test the multi threaded PDF creation. Several optimations were integrated in the new version.

#15 ♥ 0
31k Views 4 users read 5 min
support

The DLL uses new internal code to solve this issue.

I will investigate this further.

Julian

#14 ♥ 0

Has the new syncronization code been added to wPDF file version 2.7 (NET20)? I am running into similar issues while multiple threads are creating PDFs at the same time. Runs for a while and then all threads get exceptions such as:

Thread1 gets:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

while in

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at wPDF.wPDFControlDLL.DrawMetafile(Int32 env, IntPtr meta, Int32 x, Int32 y, Int32 w, Int32 h, Int32 xres, Int32 yres)
at wPDF.wPDFControlWrap.DrawMetafile(Int32 env, IntPtr meta, Int32 x, Int32 y, Int32 w, Int32 h, Int32 xres, Int32 yres)
at wPDF.PDFControl.CloseCanvas()
at wPDF.PDFControl.EndPage()

and on the other thread I get:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at wPDF.wPDFControlDLL.StartPage(Int32 env, Int32 Width, Int32 Height, Int32 Rotation)
at wPDF.wPDFControlWrap.StartPage(Int32 env, Int32 Width, Int32 Height, Int32 Rotation)
at wPDF.PDFControl.StartPage(Int32 w, Int32 h, Boolean landscape)
at wPDF.PDFControl.StartPage(ePage format, Boolean landscape)
at wPDF.PDFControl.StartPage()

Thank you for any help on this!! 🙂

#13 ♥ 0

Hi Julian

I've sent the source code by email to you.

Kind Regards
Fabrizio

#12 ♥ 0
support

Hi stffabi,

Yes, please send me that code. I will post it in an update.

Julian

#11 ♥ 0

Can you at least post the details here. I'd very much appreciate knowing your solution.

#10 ♥ 0

Hi Julian

I've taken a look into the c# source code of the wrapper class. The problem I found out, are the calls from the wPDFControlWrap calls to the static wPDFControlDLL class. Only one thread could actually call a function on the static wPDFControlDLL, that goes to the wpdfControl02.dll. I synchronized the calls and now everything works just fine. Tried 1000 loops with 4-10 threads without any problem.

If you would like I can send you the modified code of the wPDFControlWrap and wPDFControlDLL class by mail?

Kind Regards
Fabrizio

#9 ♥ 0
support

Hi,

the DLL itself (the code) is actually threadsave but there are problems with the loading/unloading of DLLs in threads. I actually don't know how to overcome this in .NET. Technically there should be no problem.

Julian Ziersch

#8 ♥ 0

Hi Julian

If you could take a look into that, that would be great.

Regards
Fabrizio

#7 ♥ 0

Same here sometimes, I get the exception that the page couldn't be started because there wasn't a begindoc call. but the call was there, and somethimes it just works fine.

It would be nice if there would be a bugfix for this soon.

#6 ♥ 0

... and in my last multi-threaded test run, the following exception:

Object reference not set to an instance of an object.
   at wPDF.wPDFControlDLL.DrawMetafile(Int32 env, IntPtr meta, Int32 x, Int32 y, Int32 w, Int32 h, Int32 xres, Int32 yres)
   at wPDF.wPDFControlWrap.DrawMetafile(Int32 env, IntPtr meta, Int32 x, Int32 y, Int32 w, Int32 h, Int32 xres, Int32 yres)
   at wPDF.PDFControl.CloseCanvas()
   at wPDF.PDFControl.EndPage()
   at MyNamespace.PdfPrintController.OnEndPage(PrintDocument document, PrintPageEventArgs e) in D:\mysource\PdfPrintController.cs:line 48
   at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
   at System.Drawing.Printing.PrintController.Print(PrintDocument document)
   at System.Drawing.Printing.PrintDocument.Print()
   at MyNamespace.PrintIdentifiersPDF.Print() in d:\mysource\printidentifierspdf.cs:line 117
#5 ♥ 0

When I'm using it in a multi-threaded environment, with multiple PDF's being generated at once, each thread with its own instance of the .NET wrapper class, I'm getting occasional exceptions which I'm having trouble finding any reason for. The exception is:

Object reference not set to an instance of an object.
   at wPDF.wPDFControlDLL.EndPage(Int32 env)
   at wPDF.wPDFControlWrap.EndPage(Int32 env)
   at wPDF.PDFControl.EndPage()
   at Mynamespace.Printing.PdfPrintController.OnEndPage(PrintDocument document, PrintPageEventArgs e)
   at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
   at System.Drawing.Printing.PrintController.Print(PrintDocument document)
   at System.Drawing.Printing.PrintDocument.Print()
   at Mynamespace.PrintIdentifiersPDF.Print()

Any ideas what would cause this? I've never had this happen in a single threaded use. Thanks.

#4 ♥ 0

How about the ActiveX Control itself when used via the .NET wrapper? The documentation for the ActiveX control says:

"Plaese note that the DLL can currently not work multithreaded."

Greg

#3 ♥ 0
support

Hi,

the wrapper uses threadsave abstractions. The C# code is also included.

Julian

#2 ♥ 0

Are the .NET wrapper and the PDF control itself thread safe? The license we own is:

PDFControl V2.35
SITE License

Thanks.

#1 ♥ 0