Any suggestions for resolving the XPSDocument GetFixedDocumentSequence performance issues?

I am trying to provide a preview of XPS documents without freezing my UI thread. Opening a document is fast enough, but when I call GetFixedDocumentSequence (), my user interface stops responding for several seconds while the document is being cleaned.

// creating the doc is fine (0.005 seconds)
XpsDocument doc=new XpsDocument("BigFile.xps",FileAccess.Read);
// this hangs the UI for several seconds
FixedDocumentSequence seq=XpsDocument.GetFixedDocumentSequence();
// Once I have the sequence, GetPageAsync lets me pull out pages without breaking the UI
// ....

The obvious solution is to open the document in the workflow, but FixedDocumentSequence is bound to the thread that created it, so I cannot access it from the UI thread, and if I try to call GetPageAsync on the work thread, I get an exception because DocumentPages contains visual effects.

The only thing I can think of is to create the document in a separate user interface thread, paginate the document and then save these pages as XPS files that the user interface thread will open. But this seems like a terribly difficult decision. Does anyone know if there is an alternative way to get DocumentPages that doesn't rely on FixedDocumentSequence?

+5
source share

All Articles