批量打印异常
在将多个 .xps 文档打印到物理打印机时,我收到此错误文档
Dim defaultPrintQueue As PrintQueue = GetForwardPrintQueue(My.Settings.SelectedPrinter)
Dim xpsPrintJob As PrintSystemJobInfo
xpsPrintJob = defaultPrintQueue.AddJob(JobName, Document, False)
已成功假脱机,直到发生打印作业异常
InnerException 是内存不足,无法继续执行程序。
来源是PresentationCore。 dll
我应该从哪里开始搜索?
I get this error while printing multiple .xps documents to a physical printer
Dim defaultPrintQueue As PrintQueue = GetForwardPrintQueue(My.Settings.SelectedPrinter)
Dim xpsPrintJob As PrintSystemJobInfo
xpsPrintJob = defaultPrintQueue.AddJob(JobName, Document, False)
Documents are spooled succesfully till, a print job exception occurs
The InnerException is Insufficient memory to continue the execution of the program.
The source is PresentationCore.dll
Where should i start searching?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当尝试执行由于某些资源的临时或永久限制而可能失败的任务时,我倾向于使用退避策略。这种策略已在消息队列和套接字打开等各种事物上得到遵循。
这种策略的一般过程如下。
这使得该进程在绝大多数情况下都可以全速运行,但在错误开始发生时会退出,希望为资源提供者提供恢复的时间。延迟的逐渐增加允许更严重的资源限制来恢复,并且最大尝试捕获您所说的永久错误(或需要很长时间才能恢复的错误)。
实际上,我更喜欢这种“尝试并捕获失败”的方法,而不是“检查如果可以,然后尝试”的方法,因为如果检查和尝试之间发生某些变化,后者仍然经常会失败。这被称为“寻求宽恕比请求许可更好”的方法,大多数时候这种方法对老板也很有效,而对妻子则不太常见:-)
一个特别有用的案例是一个程序它为每个短期事务打开一个单独的 TCP 会话。在较旧的硬件上,关闭的套接字(处于 TCP WAIT 状态的套接字)最终在再次需要之前消失。
但是,随着硬件变得更快,我们发现我们可以更快地打开会话和完成工作,而 Windows 的 TCP 句柄已经用完(即使增加到最大值)。
实施此策略是为了允许在事件句柄匮乏时顺利恢复,而不必重新设计通信协议来维持会话。
诚然,这有点拼凑,但这是接近生命周期结束的遗留软件,其中错误修复通常足以使其正常工作,并且它被认为没有足够的战略性来保证花费大量资金来正确修复它。
更新:PresentationCore 可能存在(更持久的)问题。这篇知识库文章指出 .NET 3.5SP1 中的 WPF 中存在内存泄漏(其中您的打印驱动程序可能是客户端)。
如果退避策略无法解决您的问题(如果是长期进程中的泄漏,则可能无法解决),您可能需要尝试应用修补程序。对我来说,我会在虚拟机中复制问题,然后修补它来测试它(但我是一个极端偏执狂)。
通过谷歌搜索
PresentationCore Insufficient memory to continue theexecution of the program
并检查第一个链接此处。在该页面上搜索字符串“与此问题相关的修补程序”。When attempting to perform tasks that may fail due to temporary or permanent restrictions on some resource, I tend to use a back-off strategy. This strategy has been followed on things as diverse as message queuing and socket opens.
The general process for such a strategy is as follows.
This allows the process to run at full speed in the vast majority of cases but backs off when errors start occurring, hopefully giving the resource provider time to recover. The gradual increase in delays allows for more serious resource restrictions to recover and the maximum tries catches what you would term permanent errors (or errors that are taking too long to recover).
I actually prefer this try-it-and-catch-failure approach to the check-if-okay-then-try one since the latter can still often fail if something changes between the check and the try. This is called the "better to seek forgiveness than ask permission" method, which also works quite well with bosses most of the time, and wives a little less often :-)
One particularly useful case was a program which opened a separate TCP session for each short-lived transaction. On older hardware, the closed sockets (those in TCP WAIT state) eventually disappeared before they were needed again.
But, as the hardware got faster, we found that we could open sessions and do work much quicker and Windows was running out of TCP handles (even when increased to the max).
Rather than having to re-engineer the communications protocol to maintain sessions, this strategy was implemented to allow graceful recovery in the event handles were starved.
Granted it's a bit of a kludge but this was legacy software approaching end-of-life, where bug fixes are often just enough to get it working and it wasn't deemed strategic enough to warrant spending a lot of money in fixing it properly.
Update: It may be that there's a (more permanent) problem with PresentationCore. This KB article states that there's a memory leak in WPF within .NET 3.5SP1 (of which your print driver may be a client).
If the backoff strategy doesn't fix your problem (it may not if it's a leak in a long lived process), you might want to try applying the hotfix. Me, I'd replicate the problem in a virtual machine and then patch that to test it (but I'm an extreme paranoid).
It was found by googling
PresentationCore Insufficient memory to continue the execution of the program
and checking the first link here. Search for the string "hotfix that relates to this issue" on that page.在将新作业添加到队列之前,您应该检查队列状态。有关 PrintQueue.IsOutOfMemory 属性和可以查询相关属性来验证队列是否处于错误状态。
当然,pax 暗示在访问打印机等资源时使用防御策略是最佳实践。对于初学者,您可能希望将添加作业的行放入
try
块中。Before adding a new job to the queue you should check the queue state. More info on PrintQueue.IsOutOfMemory property and related properties that can be queried to verify that the queue is not in an error state.
Of course pax' hint to use a defensive strategy when accessing resources like printers is best practice. For starter you may want to put the line adding the job into a
try
block.您可能需要考虑启动一个新进程来处理每个文档的打印,与打印文档的工作量相比,开销应该较低。
You might want to consider launching a new process to handle the printing of each document, the overhead should be low compared to the effort of printing the documents.