none
GetPrintJobInfoCollection() Exception RRS feed

  • Question

  • If you use a xps driver and use this code then after some print jobs randomly fails. However if you call it again it is fine. You can Ctrl+P at notepad or whatever to send many print jobs

    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

    However retry code seems to work fine. 

    Similar code is used by other software like .getJob() and this fails with same error sometimes.


    • Edited by Parhs Thursday, August 15, 2013 11:44 AM
    Thursday, August 15, 2013 11:43 AM

Answers

All replies

  • Does it behave better in this case?

    . . . .
    using( var server = new LocalPrintServer())
    {
        using( var q = server.GetPrintQueue("vp1"))
        {
            q.Refresh();
            using( var infos = q.GetPrintJobInfoCollection())
            {
                . . . .
            }
        }
    }


    • Edited by Viorel_MVP Thursday, August 15, 2013 6:19 PM
    Thursday, August 15, 2013 6:19 PM
  • I think it behaves a bit better. But got the error again.
    Thursday, August 15, 2013 6:53 PM
  • Hello,

    Thanks for your reply.

    Base on your description,you can set try -catch block  and  break loop sentence or breakpoint step-by-step debuging in while -loop, check GetPrintQueue if it's null before GetPrintJobInfoCollection() so that you capture the reason of error.

    In addition, you can refer How to: Diagnose Problematic Print Job  that de a means for performing a rapid remote diagnosis of print jobs.

    Hope these help.


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, August 16, 2013 6:59 AM
    Moderator