title: PuppeteerSharp Number of Chromium Instances
body: <p>We use PuppeteerSharp to add the ability for users to download a PDF of our application. Unfortunately sometimes a huge number of Chromium processes are started and don't stop until a server restart. </p>
  
  <p>Normally when a user downloads a pdf, 5 chromium processes start and those disappear when the download is finished. </p>
  
  <p>This is our code:</p>
  
  <pre><code>private static LaunchOptions launchOptions = new LaunchOptions
  {
      ExecutablePath = chromepath,
      Headless = true,
      DefaultViewport = ViewPortOptions
  };
  
  public static void ExportPdf(string url, string location)
  {
      try
      {
          Task&lt;string&gt; task = Task.Run&lt;string&gt;(async () =&gt; await ExportPdfASync(url, location)));
          task.Wait();
      }
      catch (Exception)
      {
          // Exception handling
      }
  }
  
  public static async Task&lt;string&gt; ExportPdfASync(string url, string location)
  {
      using (var browser = await Puppeteer.LaunchAsync(LaunchOptions))
      using (var page = await browser.NewPageAsync())
      {
          await page.SetViewportAsync(new ViewPortOptions() { Width = 1440, Height = 990, IsMobile = false, DeviceScaleFactor = 1.0 });
  
          await page.SetJavaScriptEnabledAsync(true);
          await page.GoToAsync(url);
          await page.WaitForTimeoutAsync(1500);
  
          var marginOptions = new MarginOptions()
          {
              Top = "10mm",
              Left = "10mm",
              Right = "10mm",
              Bottom = "10mm"
          };
  
          var pdfOptions = new PdfOptions()
          {
              PrintBackground = true,
              Format = PaperFormat.A4,
              MarginOptions = marginOptions,
              Landscape = landscape
          };
          await page.PdfAsync(location, pdfOptions);
      }
  
      return "";
  }
  </code></pre>
  
  <p>The browser and page are in the using blocks so, even with an error those should be disposed. </p>
  
  <p>Does anyone have a solution for this problem? We, and our servers would be very happy;)</p>
  
  <p><a href="https://i.stack.imgur.com/3NX06.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3NX06.png" alt="enter image description here"></a></p>