System.ComponentModel.Win32Exception: The parameter is σε PrinterQueueWatch.SpoolerStructs.JOB_INFO_2..ctor(IntPtr hPrinter, Int32 dwJobId)

Oct 13, 2011 at 9:49 AM


I would like to start a new discussion because after searching the 29 rest, I haven't found a solution for my problem.

Until yesterday when I was sending a single job to a printer, it worked fine. At some point I tried to send multiple print jobs to a printer (through another application that sends the jobs simultaneously to the print spooler - I can see for example 10 jobs pending... ). It seems that after first job is completed, my application crashes. The same code is used in both a desktop app and a service that I created. In the service it throws as unhandled exception that is logged in the event viewer and in the Desktop App I have added an unhandled exception handler in order to see it (because without this the application just crashed and I couldn't understand why).

The exception is the following:

System.ComponentModel.Win32Exception: The parameter is incorrect   in PrinterQueueWatch.SpoolerStructs.JOB_INFO_2..ctor(IntPtr hPrinter, Int32 dwJobId)   in PrinterQueueWatch.PrintJob.InitJobInfo()   in PrinterQueueWatch.PrintJob..ctor(IntPtr hPrinter, Int32 idJob)   in PrinterQueueWatch.PrintJobCollection.get_AddOrGetById(Int32 dwJobId, IntPtr mhPrinter)F   in PrinterQueueWatch.PrinterNotifyInfo..ctor(IntPtr mhPrinter, IntPtr lpAddress, PrintJobCollection& PrintJobs)   in PrinterQueueWatch.PrinterChangeNotificationThread.DecodePrinterChangeInformation()   in PrinterQueueWatch.PrinterChangeNotificationThread.StartThread()   in System.Threading.ThreadHelper.ThreadStart_Context(Object state)   in System.Threading.ExecutionContext.runTryCode(Object userData)   in System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)   in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)   in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)   in System.Threading.ThreadHelper.ThreadStart()Error Code: On Unhandled Exception   - Stack Trace -   

If you need any more clarifications let me know and I will reply as soon as possible.

Thanks in advance.

Feb 21, 2012 at 5:26 PM

The code is erroring out when trying to populate the job_info_2 structure using the API call GetJob().

I think it is happening because the JobId that is being added is not valid - but I'm afraid I can't imagine why that would be?