3 Replies - 820 Views - Last Post: 20 July 2013 - 10:12 AM Rate Topic: -----

#1 jaycaz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-July 13

Using DocumentPaginator's GetPageAsync Method to Print Asynchronou

Posted 16 July 2013 - 12:18 PM

I am trying to create a subclass of DocumentPaginator to retrieve pages taken from a canvas that lazily draws objects for efficiency. To do this, I want to override the GetPageAsync method to tell the canvas to load a region and then fire the GetPageCompleted event when the page is ready. However, whenever I use my DocumentPaginator object, the synchronous GetPage method is called instead.

I have tried using the PrintDialog class and passed in my DocumentPaginator to the PrintDocument method. When that failed, I tried creating my own XpsDocumentWriter and calling the WriteAsync method (which is what MSDN suggested to do for advanced printing, i.e. not synchronous). Both times, the GetPage method is being called instead of GetPageAsync. Is there a way to specify that I want the DocumentPaginator to load the pages asynchronously?

This is a follow up to the previously unanswered Stack Overflow question.

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Using DocumentPaginator's GetPageAsync Method to Print Asynchronou

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: Using DocumentPaginator's GetPageAsync Method to Print Asynchronou

Posted 18 July 2013 - 11:38 AM

Calling GetPage() seems to be completely expected behavior.

See the GetPageAsync(int) method documentation that says see the GetPageAsync(int, object) method:

Quote

The following steps illustrate how to retrieve a DocumentPage asynchronously:
  • Create a GetPageCompletedEventHandler delegate and add it to be notified of GetPageCompleted events.
  • Call GetPageAsync(Int32, Object) specifying the pageNumber desired and a unique userState, which will be used to identify the completion of the asynchronous event.
  • When the event occurs and the delegate is called, compare the event's GetPageCompletedEventArgs.UserState property with the original GetPageAsync(Int32, Object) userState parameter. (The GetPageCompletedEventArgs.PageNumber property will also match the pageNumber specified in the GetPageAsync(Int32, Object) call.)
  • When the GetPageCompletedEventArgs.UserState property matches the original GetPageAsync(Int32, Object) userState, the operation is complete and the page is ready.
  • Call GetPage to retrieve the formatted DocumentPage.


Notice the text I bolded.
Was This Post Helpful? 0
  • +
  • -

#3 jaycaz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-July 13

Re: Using DocumentPaginator's GetPageAsync Method to Print Asynchronou

Posted 18 July 2013 - 01:45 PM

Thanks for your reply, Skydiver. I understand that if I call GetPage and GetPageAsync directly, then that's the way I should do it. However, I am calling WriteAsync() from the XpsDocumentWriter and passing in the entire document paginator, and XpsDocumentWriter calls the get page methods internally. If I do this, GetPageAsync() is never called. Would you suggest that I just do the GetPage and GetPageAsync calls myself? Keep in mind that I am trying to retrieve multiple document pages and print them together, and I don't know how to do this manually (although I could learn it if need be).
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: Using DocumentPaginator's GetPageAsync Method to Print Asynchronou

Posted 20 July 2013 - 10:12 AM

If the XpsDocumentWriter is calling the synchronous version despite calling WriteAsync(), just live with it. What are you trying to gain by having your GetPageAsync() called if the XpsDocumentWriter.WriteAsync() is already doing its own asynchronous work?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1