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

前端之家收集整理的这篇文章主要介绍了在Asp.net中运行外部可执行文件的内存限制前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在.NET 4.0中运行的C#Web应用程序中使用WkhtmltoPdf从 HTML文件生成PDF.通常一切正常,除非HTML文件的大小低于250KB.一旦HTML文件大小超过该值,运行wkhtmltopdf.exe的进程就会产生如下异常.在任务管理器上,我已经看到wkhtmltopdf.exe进程的内存值没有超过40,096 K的值,我相信这就是为什么在这两者之间放弃进程的原因.

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

更多信息:
当我直接从命令行运行转换时,PDF生成正常.所以,它不太可能成为WkhtmlToPdf的问题.

错误来自localhost.我在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: 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进程的屏幕截图:

解决方法

这就是你要找的:

http://jobobjectwrapper.codeplex.com/

我找不到任何与“增加”进程的内存限制有关的内容,虽然我听说有人用MaxWorkingSet限制进程内存,但我相信这只适用于应用程序使用它之后的虚拟内存能够.

Job Object是一个很好的起点,它们只是一组易于控制的流程.

“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

原文链接:https://www.f2er.com/aspnet/247204.html

猜你在找的asp.Net相关文章