This code, which may seem useless, reproduces the problem. Another application uses http://printqueuewatch.codeplex.com/ to receive notification when a print job is sent to the printer. It works, but sometimes when you submit a print job, it gets reset here GetPrintJobInfoCollection. I threw in an internal exception. To reproduce, I send with Notepad ++ or my application a small text file about 20 times until I get a crash. If after an accident I call GetPrintJobInfoCollection, it works successfully or I repeat.
Any suggestion how to fix this?
while (true) { Thread.Sleep(10); LocalPrintServer server = new LocalPrintServer(); var q = server.GetPrintQueue("vp1"); q.Refresh();
A mistake in
System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object. Source=System.Printing StackTrace: at MS.Internal.PrintWin32Thunk.AttributeNameToInfoLevelMapping.InfoLevelCoverageList.Release() at MS.Internal.PrintWin32Thunk.EnumDataThunkObject.GetPrintSystemValuesPerPrintJobs(PrintQueue printQueue, Queue`1 printObjectsCollection, String[] propertyFilter, UInt32 firstJobIndex, UInt32 numberOfJobs) at System.Printing.PrintJobInfoCollection..ctor(PrintQueue printQueue, String[] propertyFilter) at System.Printing.PrintQueue.GetPrintJobInfoCollection() at WpfApplication7.MainWindow.button2_Click(Object sender, RoutedEventArgs e) in
source share