Visuals的批量打印到Xps导致OutOfMemoryException [英] Batch printing of Visuals to Xps leads to OutOfMemoryException

查看:122
本文介绍了Visuals的批量打印到Xps导致OutOfMemoryException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以这种方式打印到xps:

解决方案

Arthur,

我查看了 http://connect.microsoft.com 上的错误,并最终进行了测试.如描述将导致内存不足异常.

在我看来,我可以确认XPS不会在长文档上抛出内存不足的情况.从理论上(因为XPS上的操作是基于页面的,它不会尝试将整个文档加载到内存中),以及在实践中(我都使用基于XPS的报告,并且都发现失控错误) 消息加起来多达数千页.

问题可能出在单个特别大的页面上吗?例如,巨大的形象?大页面具有高DPI分辨率?如果文档中的单个对象太大而无法立即分配,则会导致内存不足异常.

我花了很多时间研究这个问题.这是与此主题相关的类似主题, 如何在WPF中生成和打印大型XPS文档?在此主题中,许多社区成员提供了一些建议,我认为值得尝试.

此外,此问题是由WPF设计引起的.我将通过内部方式提交此问题.此外.我们一定会听到您对这个问题感到沮丧.我们会积极监控论坛的对话,以期获得反馈,从而不断为我们提供帮助 改善我们的产品,因此我们已记录了此反馈.

如果此功能对您很重要,则可以将该功能请求提交给Visual Studio用户语音,Microsoft将对此予以考虑.

http://visualstudio.uservoice.com/forums/121579-visual-studio

感谢您的理解!

玩得开心!

此致


Hi,

I am printing to xps in this way:

PrintQueue queue = printQueueObject as PrintQueue;

if (queue != null)
{
    queue.Refresh();
    collator = PrintQueue.CreateXpsDocumentWriter(queue).CreateVisualsCollator();
    collator.BeginBatchWrite();

    ...
    collator.Write(visual);
    collator.EndBatchWrite();
}

After 1000 pages or so are printed, I get an OutOfMemoryException. After using a memory profiler, the problem source seems to be the following chain:

InterleavingNode

-> System.Windows.Xps.Packaging.XpsFixedPageReaderWriter
-> _parentNode (field)
--> XpsFixedDocumentReaderWriter
--> _pageCache (field of type List<IXpsFixedPageReader>)

---> 800 instances of XpsFixedPageReaderWriter

-----> 2400 instances of System.IO.StringWriter = 2400 instances of System.Text.StringBuilder

or in other words:

There seems to be a page cache that is growing all the time, while we are generating the XPS document. So if we generate a huge document with many thousands of pages we get sooner or later an OutOfMemoryException (depending on the users available memory).

There has been a similar question here:

https://connect.microsoft.com/VisualStudio/feedback/details/788507/creating-xps-document-with-visuals-collator-consumes-a-very-large-amount-of-memory

But there has never been a solution or workaround to this. I am currently using Windows 8.

Thanks

解决方案

Hi Arthur,

I reviewed the bug on http://connect.microsoft.com and tested it on my end. It will cause the out of memory exception as description.

In my view, I can confirm that XPS does not throw out-of-memory on long documents. Both in theory (because operations on XPS are page-based, it doesn't try to load whole document in memory), and in practice (I use XPS-based reporting, and seen run-away error messages add up to many thousands of pages).

Could it be that the problem is in a single particularly large page? A huge image, for example? Large page with high DPI resolution? If single object in document is too big to be allocated at once, it will lead to out-of-memory exception.

I spent a lot of time to research this issue. Here is a similar thread about this topic, How to generate and print large XPS documents in WPF? In this thread, many community member provided some suggestions, I think it worth a try.

Also, this issue is caused by WPF design. And I will submit this issue through internal way. In addition. We definitely hear your frustration on this issue. We actively monitor forum conversations in an effort to receive feedback that helps us continually improve our products, so we have logged this feedback accordingly.

If this feature is important to you, you could submit this feature request to Visual Studio User voice, Microsoft will take this into consideration.

http://visualstudio.uservoice.com/forums/121579-visual-studio

Thanks for your understanding!

Have a nice time!

Sincerely,


这篇关于Visuals的批量打印到Xps导致OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆