gpt4 book ai didi

asp.net - 在 Asp.net 中运行外部可执行文件的内存限制

转载 作者:行者123 更新时间:2023-12-02 11:02:37 25 4
gpt4 key购买 nike

我在 .NET 4.0 中运行的 C# Web 应用程序中使用 WkhtmltoPdf 从 HTML 文件生成 PDF。一般来说,除非 HTML 文件大小低于 250KB,否则一切正常。一旦 HTML 文件大小增加超过该大小,运行 wkhtmltopdf.exe 的进程就会出现如下异常。在任务管理器上,我看到 wkhtmltopdf.exe 进程的内存值不会增加超过 40,096 K 的值,我认为这就是该进程在其间被放弃的原因。

我们如何配置才能增加外部 exe 的内存限制?还有其他方法可以解决这个问题吗?

更多信息:
当我直接从命令行运行转换时,PDF 生成得很好。因此,这不太可能是 WkhtmlToPdf 的问题。

错误来自本地主机。我在DEV服务器上尝试了同样的方法,得到了相同的结果。

编辑:

More specific exception message: - For the MainModule property of the Process object, the error says - {"Only part of a ReadProcessMemory or WriteProcessMemory request was completed"}, with the NativeErrorCode value - 299.

异常(exception):

> [Exception: Loading pages (1/6) [>                                    
> ] 0% [======> ]
> 10% [======> ] 11%
> [=======> ] 13%
> [=========> ] 15%
> [==========> ] 18%
> [============> ] 20%
> [=============> ] 22%
> [==============> ] 24%
> [===============> ] 26%
> [=================> ] 29%
> [==================> ] 31%
> [===================> ] 33%
> [=====================> ] 35%
> [======================> ] 37%
> [========================> ] 40%
> [=========================> ] 42%
> [==========================> ] 44%
> [============================> ] 47%
> [=============================> ] 49%
> [==============================> ] 51%
> [============================================================] 100%
> Counting pages (2/6)
> [============================================================] Object
> 1 of 1 Resolving links (4/6)
> [============================================================] Object
> 1 of 1 Loading headers and footers (5/6)
> Printing pages (6/6) [>
> ] Preparing [=>
> ] Page 1 of 49 [==>
> ] Page 2 of 49 [===>
> ] Page 3 of 49 [====>
> ] Page 4 of 49 [======>
> ] Page 5 of 49 [=======>
> ] Page 6 of 49 [========>
> ] Page 7 of 49 [=========>
> ] Page 8 of 49 [==========>
> ] Page 9 of 49 [============>
> ] Page 10 of 49 [=============>
> ] Page 11 of 49 [==============>
> ] Page 12 of 49 [===============>
> ] Page 13 of 49 [================>
> ] Page 14 of 49 [==================>
> ] Page 15 of 49 [===================>
> ] Page 16 of 49 [====================>
> ] Page 17 of 49 [=====================>
> ] Page 18 of 49 [======================>
> ] Page 19 of 49 [========================>
> ] Page 20 of 49 [=========================>
> ] Page 21 of 49 [==========================>
> ] Page 22 of 49 [===========================>
> ] Page 23 of 49 [============================>
> ] Page 24 of 49 [==============================>
> ] Page 25 of 49 [===============================>
> ] Page 26 of 49 [=================================>
> ] Page 27 of 49 [==================================>
> ]

我使用的代码:

    var fileName = " - ";
var wkhtmlDir = ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfExecutablePath];
var wkhtml = ConfigurationManager.AppSettings[Constants.AppSettings.ExportToPdfExecutablePath] + "\\wkhtmltopdf.exe";
var p = new Process();


string switches = "";
switches += "--print-media-type ";
switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 5mm --margin-left 5mm ";
switches += "--page-size A4 ";
switches += "--disable-smart-shrinking ";

var startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
FileName = wkhtml,
Arguments = switches + " " + url + " " + fileName,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput=true,
WorkingDirectory=wkhtmlDir
};

p.StartInfo = startInfo;
p.Start();

WkHtmlToPdf.exe 进程的调试器屏幕截图:

enter image description here

最佳答案

这就是您要找的:

http://jobobjectwrapper.codeplex.com/

我找不到任何其他与“增加”进程内存限制有关的内容,尽管我听说有人使用 MaxWorkingSet 限制进程内存,但我相信这只是在应用程序使用完所有可用的虚拟内存后。

作业对象是一个很好的起点,它们只是易于控制的流程的集合。

"With this library you can create job objects, create and assign a process to the job, control process and job limits, and register for the various process- and job-related notification events."

这也可能有用:

Calling wkhtmltopdf to generate PDF from HTML

关于asp.net - 在 Asp.net 中运行外部可执行文件的内存限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com