这段看似无用的代码重现了问题。另一个应用程序使用 http://printqueuewatch.codeplex.com/ 在打印作业发送到打印机时收到通知。它可以工作,但有时当您发送打印作业时,它会在 GetPrintJobInfoCollection 处崩溃。我已经粘贴了内部异常。为了重现,我使用 Notepad++ 或我的应用程序发送了大约 20 次小文本文件,直到我崩溃。如果在崩溃后我调用 GetPrintJobInfoCollection 它会成功运行,或者我重试。
任何建议如何解决这个问题?
while (true)
{
Thread.Sleep(10);
LocalPrintServer server = new LocalPrintServer();
var q = server.GetPrintQueue("vp1");
q.Refresh();
// Debug.WriteLine(q.IsBusy);
PrintJobInfoCollection infos = null;
infos = q.GetPrintJobInfoCollection();
}
错误
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