system out of memory exception

Apr 20, 2015 at 3:31 PM

I have ran into an issue on server where there are 1600+ print queues created. When adding the print queue to the PrinterMonitorComponent, I get an out of memory issue at +- 550 devices.

I understand this is a 32 bit issue, when compiling for 64bit this issue goes away, how ever the PrinterMonitorComponent.JobAdd does not fire. I have download your latest build to test with and still no success.

I would really appreciate some assistance.

Kind regards
Apr 21, 2015 at 8:56 AM
Wow - I'm impressed that it gets that far...but unfortunately I have no way of testing it to 500+ devices.

Is there a stack dump when it has the out-of-memory error - or can you turn on the logging and see if you can get more info as to where it is crashing?
Apr 21, 2015 at 9:46 AM
Hi Merrion

Thank you for the prompt response. I will try get a stack dump or turn the logging to get you some more information.

I am able to give you some code that will generate a command file that will add as many print queues as you require. We test against a nul: port for this sort of thing. Would this be of interest or assistance to you?

Apr 21, 2015 at 11:29 AM
I would be interested, yes.

Tracing can be done by setting the PrinterMonitorComponent trace switch to "Verbose" in the application config file, and directing the output to a file.
Apr 21, 2015 at 2:54 PM
He Merrion

Below is the code. It will generate a command file that you can run. You need to make sure you have a nul: port created an you will need to provide the name of an installed print driver.

I will post the output from the debugging shortly.
    Sub Main()
        Dim printers As Integer
        Dim i As Integer = 1
        Dim driver As String = Nothing

        Dim log As String = "C:\Temp\AddPrintQueues" & Date.Now.ToString("yyyyMMdd") & ".cmd"
        Dim objwriter As New StreamWriter(log, True)

        Console.WriteLine("How many print queues do you want to created.")
        printers = Console.ReadLine

        Console.WriteLine("Please provide print driver to user")
        driver = Console.ReadLine

        While i <= printers
            objwriter.WriteLine("Cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnmngr.vbs -a -p " & "Test_Printer_" & i & " -m """ & driver & """ -r nul:""")
            i = i + 1
        End While
    End Sub
Apr 21, 2015 at 3:14 PM
Here is the stacktrace

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.OutOfMemoryException
at System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean)
at System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean)
at System.Threading.WaitHandle.WaitOne(Int32, Boolean)
at PrintQueueWatch.PrinterChangeNotificationThread.StartThread()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
Apr 21, 2015 at 3:42 PM
From reading around it seems a thread can only have a maximum of 64 wait handles being waited on at any given time - this is (most likely) what is causing the problem.