Vista 64 printer hang

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
TDWiseley
Posts: 18
Joined: Wed Jul 18 2007

Vista 64 printer hang

Post by TDWiseley »

Am doing development work on a Vista 64 box, using C#/2.0. Can create an Amyuni Convertor 4.08 printer and use it, etc. However, during debugging, if I stop during a PrintPage event, the printer has a document stuck in it which cannot be deleted, and the software hangs entering the PrintPage event next time this printer is used. The only solution I have found is to delete the printer, and then reboot the system (which is required for the delete to happen). Is there a work-around for this situation, since if an error in the PrintPage event occurs at a customer site, they're not going to want to delete/reboot, etc?
Devteam
Posts: 119
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Re: Vista 64 printer hang

Post by Devteam »

Event handling requires some additional consideration under 64-bit systems. The problem is the following:
When a 32-bit application prints to a 64-bit driver under a 64-bit OS, the 32-bit application does not directly interact with the printer driver but another process is involved: splwow64.exe. This additional process creates a deadlock if the same thread is calling the printer and handling events sent by the printer.

We have investigated this issue in details and the only solution is to handle events in a thread that is separate from the thread that is printing. Rather than rebooting the system, you can get rid of the document in the print queue by terminating the splwow64.exe process from the task manager or by restarting the print spooler service.
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - https://www.amyuni.com
TDWiseley
Posts: 18
Joined: Wed Jul 18 2007

Re: Vista 64 printer hang

Post by TDWiseley »

Thanks, deleting the splwow64 routine allowed me to do a cleanup w/ having to reboot

Don't really understand the details mentioned in the second paragraph about handling the events in a separate thread. Do you have any samples or other resources I can look into for implementing this?

Thanks in advance
shopsinc
Posts: 1
Joined: Thu Nov 18 2010

Re: Vista 64 printer hang

Post by shopsinc »

Do you have any more information on this solution? We are having a similar problem that seems to be a combination of this dead lock issue, and this exclusive lock issue (http://www.amyuni.com/forum/viewtopic.p ... ow64#p8673).

So we have one process that deadlocks, freezes the splwow64 and then none of the the other apps can print. This is a rather catastrophic failure mode.

This occurs on win2k8_64 and win7_64. Our processes are 32 bit.

I'm trying to work around it by implementing your suggestion of handling events on a different thread than the printing, but I was wondering if you have more detail on what you mean by that. Do you mean I should redirect all the events to be executed on a different thread? or that the .Print() call should be made on a different thread? What about accessing properties on the printer as these seem to deadlock too?

Any advice you can give would be much appreciated.

Thanks!
-Charlie
mikeng
Posts: 1
Joined: Tue Dec 07 2010

Re: Vista 64 printer hang

Post by mikeng »

We also have a 32-bit application and are experiencing similar problems when we are running on a 64-bit OS installation. It works great on a 32-bit OS :) , but in 64 bit environment, when it's going through splwow64 i takes 2 minutes to print a 3 pages long document. :(

I have searched this forum and many other places on the web but can't find no solution that works and converts acceptably fast.

If anyone have solved this and have some code example or advices then that would be very much appreciated.

Thanks in advance.
/Mikael
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Re: Vista 64 printer hang

Post by Jose »

Events fired by the PDF Converter behave differently on 32-bit applications running under a 64-bit OS than 32-bit applications running under a 32-bit OSs.

In the case of a 32bit application running on a 64bit Os, the printing occurs within a process named SPLWOW64 and this process locks the calling application whenever GDI instructions are issued and the SPLWOW64 needs to be the main process.

The calling application cannot process messages within the same thread when doing GDI calls such as StartDoc. You do not see the issue with other printers because these printers do not send messages to the printing application.

The issue does not happen if broadcasting messages or capturing events is disabled (not used) or if you print to the PDF Converter from a different thread than the one that enabled the message broadcasting.

Below is simplified C# example that illustrates how to handle events fired by the PDF Converter and how to process a print job from another thread.

using System.Threading;


////////////////////////////////////////////////////////
//create PDF printer constants
//this is the printer name installed by default
const string PDFprinter = "Amyuni PDF Converter";
const string strLicenseTo = "Amyuni Tech Support Eval";
const string strActivationCode = "07EFCDAB01000100A1F045A918107C274DA661C2991C502C4FD20D64399779DC9E0FE0C88DF61EFA59C265C0075D646D2AF7833AEB8A";

//Added a reference to the cdintf450.dll
static CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfExClass();

const Int32 sNoPrompt = 0x01;
const Int32 sUseFileName = 0x02;

/// <summary>
/// This function starts the event handling process. In this example
/// the function is started by clicking on button
/// </summary>
private void btnStart_Click(object sender, System.EventArgs e)
{
//Initailize printer
PDF.DriverInit(PDFprinter);
PDF.EnablePrinter(strLicenseTo, strActivationCode);

PDF.SetDefaultPrinter();

//start capturing events
PDF.CaptureEvents (1);

//Create Delegates to handle events
PDF.EnabledPre += new CDIntfEx._DCDIntfEvents_EnabledPreEventHandler(this.PDF_EnabledPre);
PDF.StartDocPre += new CDIntfEx._DCDIntfEvents_StartDocPreEventHandler(this.PDF_StartDocPre);
PDF.StartDocPost += new CDIntfEx._DCDIntfEvents_StartDocPostEventHandler(this.PDF_StartDocPost);
PDF.EndDocPre += new CDIntfEx._DCDIntfEvents_EndDocPreEventHandler(this.PDF_EndDocPre);
PDF.EndDocPost += new CDIntfEx._DCDIntfEvents_EndDocPostEventHandler(this.PDF_EndDocPost);

Debug.WriteLine("Initializing Events!.....");

}

/// <summary>
/// This event is fired each time output is sent to the PDF Converter
/// </summary>
public void PDF_EnabledPre()
{
Debug.WriteLine("PDF_EnabledPre fired!");

PDF.DefaultFileName = @"c:\temp\amyuni.pdf";
PDF.FileNameOptions = sNoPrompt + sUseFileName + sBroadCastMessages;

//This needs to be called each time printing out put is sent to printer
PDF.EnablePrinter ( strLicenseTo, strActivationCode );
}

/// <summary>
/// Event fired before StartDoc is handled
/// </summary>
public void PDF_StartDocPre ()
{
Debug.WriteLine("PDF_StartDocPre fired!");
}

/// <summary>
/// Event fired after StartDoc is handled
/// </summary>
/// <param name="JobID"></param>
/// <param name="hDC"></param>
public void PDF_StartDocPost(int JobID , int hDC )
{
Debug.WriteLine("PDF_StartDocPost fired!");
}

/// <summary>
/// Event before EndDoc is handled
/// </summary>
public void PDF_EndDocPre(int JobID , int hDC )
{
Debug.WriteLine("PDF_EndDocPre fired! JobID: " + JobID);
}

/// <summary>
/// Event after EndDoc is handled
/// </summary>
public void PDF_EndDocPost(int JobID , int hDC )
{
Debug.WriteLine("PDF_EndDocPost fired!");
Debug.WriteLine(PDF.GetGeneratedFilename());
}

private void Form1_Closed(object sender, System.EventArgs e)
{
//Clean up
PDF.CaptureEvents ( 0 );
PDF.FileNameOptions = 0;
}


/// <summary>
/// This function will send a print job to the PDF Converter from
/// a different thread than the process that is handleing the events
private void btnThread_Click(object sender, EventArgs e)
{
Thread oThread = new Thread(new ThreadStart(PrintDoc)); //PrintWordInThread
try
{
oThread.Start();
}
catch (ThreadStateException)
{
Console.WriteLine("problem");
}
}


/// <summary>
/// This prints a document
/// </summary>
public void PrintDoc()
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler (this.PrintSomething);
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}


public void PrintSomething(object sender, PrintPageEventArgs ev)
{
Font printFont = new Font("Arial", 36);
float fltY = 50;
using (Brush brush = new SolidBrush(System.Drawing.Color.Black))
{
ev.Graphics.DrawString("Hello World", printFont,
brush, 50, fltY);
}
}


Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite
Post Reply