We have a static method that returns pdf bytes but there is uncertain times the pdf it generates is blank/distorted. Trying to figure out if an instance of an html to PDF generator being inside a static method causes the output to fail by not being able to generate the expected content in the pdf.
Sample:
public class EvoPDFUtility
{
public static byte[] ConvertHtmlToPdf(string html)
{
var htmlToPdfGenerator = new EvoPDF();
return htmlToPdfGenerator.Convert(html);
}
}
Is the instance inside the static method becomes shared to and the same everytime the static method is called?
No, htmpToPdfGenerator
has local scope .
It is instantiated separately every time the static method is called and eligible for garbage collection as soon as that method exits.
Since each invocation of the static method references only a locally-scoped variable, the method is also thread safe.
Eric is right. It's not because it's a static function. It's more likely:
Does it have issues generating the PDF several times against the same (good) HTML?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.