Q: Is the PDFViewCtrl threadSafe ?
I am trying to send parts of a large PDF to the client and merge it there:
using (PDFDoc tempDoc = new PDFDoc(stream, streamSize))
{
tempDoc.InitSecurityHandler();
Page src_page = tempDoc.GetPage(1);
_pdfDoc.PageInsert(_pdfDoc.GetPageIterator(pageTo), src_page);
_pdfView.UpdatePageLayout();
_pdfDoc.PageRemove(_pdfDoc.GetPageIterator(pageTo + 1));
_pdfView.UpdatePageLayout();
tempDoc.Close();
}
The pdf starts rendering wrong when I do this. Sample attached.
If I had a thread.sleep in the pagechanged: Thread.Sleep(250); it works fine.
I have tried adding lock, etc. but can’t get it to work.
A:
Yes, PDFNet is thread safe, however you need to lock document associated with PDFViewCtrl for editing, or even when accessing the doc in read mode. For example
using (PDFDoc tempDoc = new PDFDoc(stream, streamSize))
{
tempDoc.InitSecurityHandler();
Page src_page = tempDoc.GetPage(1);
_pdfDoc.Lock();
_pdfDoc.PageInsert(_pdfDoc.GetPageIterator(pageTo), src_page);
_pdfDoc.PageRemove(_pdfDoc.GetPageIterator(pageTo + 1));
_pdfDoc.Unlock();
_pdfView.UpdatePageLayout();
tempDoc.Close();
}