How do I use Async & MultiThreading for Html-To-PDF?

Async and Threading is useful when genearting PDFs in C# and VB.Net in batches or for high performance.

Async

IronPDF fully supports .Net Framework 4, and as such working with async functions requires a few extra lines of code. Task.Run requires .Net Framework 4.5+, or for the Microsoft Byte-Code Library to be installed into a .Net 4 project via NuGet.


private async Task <IronPdf.PdfDocument> RenderPdfAsync( string Html , IronPdf.PdfPrintOptions PrintOptions = null )

{

  var Renderer = new IronPdf.HtmlToPdf();

  if(PrintOptions!=null){

    Renderer.PrintOptions = PrintOptions;

  }

  return Renderer.RenderHtmlAsPdf(Html);

}
    
    Private Async Function RenderPdfAsync(ByVal Html As String, Optional ByVal PrintOptions As IronPdf.PdfPrintOptions = Nothing) As Task(Of IronPdf.PdfDocument)
        Dim Renderer = New IronPdf.HtmlToPdf
        If (Not (PrintOptions) Is Nothing) Then
            Renderer.PrintOptions = PrintOptions
        End If
        
        Return Renderer.RenderHtmlAsPdf(Html)
    End Function
VB   C#

Multi-Threading

For high performance, IronPDF fully supports multithreading. The easiest way to achieve this by using the native command Paralllel.ForEach

https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-write-a-parallel-foreach-loop-with-partition-local-variables