Process/Print PDF document using Aspose.PDF for .NET - Managed Debugging Assistant ‘ContextSwitchDeadlock’

if (i == 1)
{
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Document printing code goes here
// Print document using printer and page settings
ps = printDialog.PrinterSettings;
viewer.PrintDocumentWithSettings(pgs, ps);
}
else
{
Status = “CANCEL”;
break;
}
}
else
{
viewer.PrintDocumentWithSettings(pgs, ps);
}

When I run the program in Visual Studio, I get the following error.
ko-KR_남성암 5종 v3_38_57244_결과지(수정).pdf (4.7 MB)
ko-KR_남성암 5종 v3_38_57248_결과지(수정).pdf (4.8 MB)
ko-KR_남성암 5종 v3_38_57309_결과지(수정).pdf (5.0 MB)
Spool.PNG (32.4 KB)

Managed Debugging Assistant ‘ContextSwitchDeadlock’ :
‘The CLR has been unable to transition from COM context 0xdfc5c0 to COM context 0xdfc678 for 60 seconds.
The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages.
This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time.
To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during
long running operations.’
TimeOut.PNG (26.4 KB)

@hbhur102

It seems like you are printing PDF document in multi-threading mode. Would you kindly share a sample console application which is able to reproduce the issue in our environment. We will test the scenario and address it accordingly.

We are using PDF library Version 19.x

Program.zip (1.2 KB)

We created a Console App that sequentially prints’*.pdf’ files in the directory where the executable file is located. If you put the pdf file shared above into the same folder and run it, the spool execution will stop following pdf page.

ko-KR_남성암 5종 v3_38_57248_결과지(수정) 37.pdf (4.7 MB)

Spool.PNG (11.0 KB)

@hbhur102

We have tested the scenario in our environment using your code snippet and Aspose.PDF for .NET 20.6. We were unable to notice any issue. Please check attached console output. cout.png (15.6 KB)

Would you kindly try the following options at your end in order to prevent the error that you are facing:

  • Use latest version of the API
  • Make sure to set Debug mode to x64 or AnyCPU
  • Debug -> Exceptions -> Managed Debug Assistants menu in Visual Studio and uncheck the ContextSwitchDeadlock

What is different from x64 and AnyCpu??? Thank you for doing well with x64.

@hbhur102

Some PDF documents (due to their complex structure and large size) need more memory to be processed. x64 and AnyCPU mode of debugging allows a program to have access to full available memory.