[Solved]Exception - R6016 – not enough space for thread data

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
BillMunro
Posts: 9
Joined: Tue Nov 20 2007

[Solved]Exception - R6016 – not enough space for thread data

Post by BillMunro »

I am having a problem with the trial version of PDF Creator 3.0. In my test application I create a small class that wraps acPDFCreatorLib.

The class doesn’t do much; it just calls the Merge method to merge a watermark (pdf) into another PDF document. It works fine. In the button click handler of my test app I instantiate my wrapper class, and then call the method that calls Merge. It works fine for the first couple of times but then I get the exception shown below.

If I persist my class across button clicks, rather than creating and destroying class instances on each click, I don’t see the error.

Is it possible that this issue only exists in the trial version? I don’t have a license key to test with. (I will be purchasing PDF Creator soon). Or is there something wrong with my code or with PDF Creator?

Here is my code:

Code: Select all

   class PDFWatermark
    {
        public PDFWatermark()
        {
            acPDFCreatorLib.Initialize();
        }

        ~PDFWatermark()
        {
            acPDFCreatorLib.Terminate();
        }

        // Add Simple watermark;
        // Writes to file;
        public TimeSpan MergeWatermark(string originalFilespec, string watermarkFilespec, string finalFile)
        {
            DateTime startTime = DateTime.Now;

            using (FileStream file1 = new FileStream(originalFilespec, FileMode.Open, FileAccess.Read))
            using (FileStream file2 = new FileStream(watermarkFilespec, FileMode.Open, FileAccess.Read))
            using (FileStream file3 = new FileStream(finalFile, FileMode.Create, FileAccess.Write))
            using (IacDocument doc1 = new IacDocument(null))
            using (IacDocument doc2 = new IacDocument(null))
            {
                try
                {
                    // Opend the pdf file we want to add watermarks to
                    doc1.Open(file1, "");

                    // Open the watermark pdf file
                    doc2.Open(file2, "");

                    // merge the two documents: doc2 is merged into doc1.
                    doc2.Merge(doc1, 1);  // 2nd arg: 1=merge doc2 to every page of doc1
                                          //          2=merge doc2 to the first page of doc1

                    // save the result to a third file
                    doc2.Save(file3);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    file1.Close();
                    file2.Close();
                    file3.Close();
                }
            }
-Bill

Exception Details:

R6016 – not enough space for thread data. […] Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Amyuni.PDFCreator.IacDocument.Dispose(Boolean disposing)
at Amyuni.PDFCreator.IacDocument.Dispose()
at PDFAddWatermark.PDFWatermark.MergeWatermark(String originalFilespec, String watermarkFilespec, String finalFile) in C:\Applications\DotNetTools\PDFAddWatermark\PDFAddWatermark\PDFWatermark.cs:line 77
at PDFAddWatermark.frmAddWatermark.button1_Click(Object sender, EventArgs e) in C:\Applications\DotNetTools\PDFAddWatermark\PDFAddWatermark\frmAddWatermark.cs:line 37
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
BillMunro
Posts: 9
Joined: Tue Nov 20 2007

RE: Exception - R6016 – not enough space for thread data

Post by BillMunro »

Never mind. I solved the problem by having my wrapper class implement IDisposable.

-Bill
Post Reply