【问题标题】:Any suggestions for dealing with XpsDocument GetFixedDocumentSequence performance issues?关于处理 XpsDocument GetFixedDocumentSequence 性能问题的任何建议?
【发布时间】:2010-06-25 16:05:10
【问题描述】:

我正在尝试在不挂起我的 UI 线程的情况下提供 XPS 文档的实时预览。打开文档的速度足够快,但是当我调用 GetFixedDocumentSequence() 时,我的 UI 会在几秒钟内无响应,而文档突然消失。

// 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
// ....

显而易见的解决方案是在工作线程上打开文档,但 FixedDocumentSequence 与创建它的线程绑定,因此我无法从 UI 线程访问它,如果我尝试从工作线程调用 GetPageAsync线程我得到一个异常,因为 DocumentPages 包含视觉效果。

我唯一能想到的就是在单独的 UI 线程上创建文档,将文档分成页面,然后将这些页面保存为 UI 线程打开的 XPS 文件。但这似乎是一个非常复杂的解决方案。有谁知道是否有另一种方法可以获取不依赖 FixedDocumentSequence 的 DocumentPages?

【问题讨论】:

    标签: wpf xpsdocument


    【解决方案1】:

    有一个简单的解决方案。它被称为多线程 UI,它可以帮助您做所有事情,但有两个 UI 线程而不是一个。这意味着您的 XPS 可以毫无问题地加载到单独的 UI 线程上。我过去自己实现过,很好。

    http://blogs.msdn.com/b/dwayneneed/archive/2007/04/26/multithreaded-ui-hostvisual.aspx

    【讨论】:

      猜你喜欢
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多