Mã này có vẻ như vô ích nó tái tạo sự cố. Một ứng dụng khác đang sử dụng http://printqueuewatch.codeplex.com/ để được thông báo khi lệnh in được gửi đến máy in. Nó hoạt động nhưng đôi khi bạn gửi một công việc in nó treo ở đây GetPrintJobInfoCollection. Tôi đã dán ngoại lệ bên trong. Để tái tạo, tôi gửi bằng Notepad ++ hoặc ứng dụng của tôi một tệp văn bản nhỏ khoảng 20 lần cho đến khi tôi gặp sự cố. Nếu sau sự cố tôi gọi GetPrintJobInfoCollection, nó hoạt động thành công hoặc tôi thử lại.GetPrintJobInfoCollection() Ngoại lệ đôi khi
Bất kỳ đề xuất nào về cách sửa lỗi này?
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();
}
Lỗi trong
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