Threading issue with PDF Converter 2.06

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
marco
Posts: 6
Joined: Wed Nov 06 2002

Threading issue with PDF Converter 2.06

Post by marco » Tue Nov 26 2002

Hi, I am using C# to develop an application which uses your PDF converter and I am running into issues when I call the CDIntf from a thread. But let me explain more in detail what is happening.

I have an ATL COM component which creates an instance of the CDIntf:

Code: Select all

CDIntf::ICDIntfPtr pdfPrn = NULL;
hr = pdfPrn.CreateInstance(__uuidof(CDIntf::CDIntf));
Everything works fine as long as I am in a single thread. When I put the code that calls my COM object (and thus the CDIntf) the call to CreateInstance gets stuck until the thread is joined.

I've tried also to create the CDIntf object directly in C# by using COM interop with the same results.

Code: Select all

class Class1
{
    [STAThread]
    static void Main(string[] args)
    {
        CDIntf.CDIntf pdfPrn = new CDIntf.CDIntfClass();
        pdfPrn.DriverInit("PDFConverter");
			
        pdfPrn.FileNameOptionsEx = 0x20000 + 0x1;

        //my printing code here
        
        pdfPrn.FileNameOptions = 0x0;

       System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfPrn);
       pdfPrn = null;
    }
}
The code above works. But as long as I put the call CDIntf.CDIntf pdfPrn = new CDIntf.CDIntfClass(); inside a thread it doesn't work anymore.

Code: Select all

class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			
			MyThread t = new MyThread();
			t.start();
			
			Thread.Sleep(10000);
		
			t.join();
		}
	}


	class MyThread
	{
		Thread tr = null;

		public MyThread() 
		{
			tr = new Thread(new ThreadStart(this.run));
		}

		
		public void start()
		{
			tr.Start();
		}


		public void join() 
		{
			tr.Join();
		}


		public void run()
		{
			CDIntf.CDIntf pdfPrn = new CDIntf.CDIntfClass();
			pdfPrn.DriverInit("PDFConverter");
			


			pdfPrn.FileNameOptionsEx = 0x20000 + 0x1;

			//printing code here

			pdfPrn.FileNameOptions = 0x0;

			System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfPrn);
		
			pdfPrn = null;
		}
	}
The thread gets stuck at the call CDIntf.CDIntf pdfPrn = new CDIntf.CDIntfClass(); and returns only when the Join is called on it.

Any ideas in regard?

- Marco

Post Reply